Exemplo n.º 1
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"'));
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param SchemaContainer $schemaContainer
  * @param array           $mapping
  */
 private function mapInterfaces(SchemaContainer $schemaContainer, array $mapping)
 {
     foreach ($mapping as $name => $interfaceMapping) {
         $interface = $this->createInterface($name, $interfaceMapping);
         $schemaContainer->addInterface($interface);
     }
 }