Example #1
0
 /**
  * @param SchemaContainer $schemaContainer
  * @param array           $mapping
  */
 private function mapMutation(SchemaContainer $schemaContainer, array $mapping)
 {
     $mutationSchema = $schemaContainer->getMutationSchema();
     if (null === $mutationSchema) {
         $mutationSchema = new Mutation();
         $schemaContainer->setMutationSchema($mutationSchema);
     }
     $this->populateFieldContainer($mutationSchema, $mapping);
 }
 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');
         }
     }
 }
Example #3
0
 /**
  * @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"'));
         }
     }
 }