/** * @param SchemaContainer $schemaContainer * @param array $mapping */ private function mapQuery(SchemaContainer $schemaContainer, array $mapping) { $querySchema = $schemaContainer->getQuerySchema(); if (null === $querySchema) { $querySchema = new Query(); $schemaContainer->setQuerySchema($querySchema); } $this->populateFieldContainer($querySchema, $mapping, true); }
/** * @param SchemaContainer $schemaContainer */ public function guess(SchemaContainer $schemaContainer) { $fieldContainers = $schemaContainer->getTypes() + $schemaContainer->getInterfaces(); if (null !== ($query = $schemaContainer->getQuerySchema())) { $fieldContainers[] = $query; } foreach ($fieldContainers as $fieldContainer) { $containerContext = new ContainerContext($fieldContainer, $schemaContainer); $this->guessFields($containerContext); $this->guessTypeResolveConfig($containerContext); } }
private function fixNames(SchemaContainer $schemaContainer) { if (null !== ($query = $schemaContainer->getQuerySchema())) { $query->setName('Query'); if (null === $query->getDescription()) { $query->setDescription('The query root of this schema'); } } if (null !== ($mutation = $schemaContainer->getMutationSchema())) { $mutation->setName('Mutation'); if (null === $mutation->getDescription()) { $mutation->setDescription('The mutation root of this schema'); } } }
/** * @param string $path * @param SchemaContainer $schemaContainer */ private function loadFile($path, SchemaContainer $schemaContainer) { $config = Yaml::parse($this->getFileContent($path)); foreach ($config as $type => $mapping) { switch ($type) { case 'query': $querySchema = $schemaContainer->getQuerySchema(); if (null === $querySchema) { $querySchema = new Query(); $schemaContainer->setQuerySchema($querySchema); } $this->populateFieldContainer($querySchema, $mapping); break; case 'mutation': $mutationSchema = $schemaContainer->getMutationSchema(); if (null === $mutationSchema) { $mutationSchema = new Query(); $schemaContainer->setMutationSchema($mutationSchema); } $this->populateFieldContainer($mutationSchema, $mapping); break; case 'types': foreach ($mapping as $name => $typeMapping) { $type = $this->createType($name, $typeMapping); $schemaContainer->addType($type); } break; case 'interfaces': foreach ($mapping as $name => $interfaceMapping) { $interface = $this->createInterface($name, $interfaceMapping); $schemaContainer->addInterface($interface); } break; default: throw new \UnexpectedValueException(sprintf('Unsupported key "%s"')); } } }