Пример #1
0
 public function testDefinesAMutationSchema()
 {
     $blogSchema = new Schema($this->blogQuery, $this->blogMutation);
     $this->assertSame($this->blogMutation, $blogSchema->getMutationType());
     /** @var \Fubhy\GraphQL\Type\Definition\FieldDefinition $writeMutation */
     /** @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType $writeMutationType */
     $writeMutation = $this->blogMutation->getFields()['writeArticle'];
     $writeMutationType = $writeMutation->getType();
     $this->assertEquals('writeArticle', $writeMutation->getName());
     $this->assertSame($this->blogArticle, $writeMutationType);
     $this->assertEquals('Article', $writeMutationType->getName());
 }
Пример #2
0
 /**
  * Extracts the root type of the operation from the schema.
  *
  * @param Schema $schema
  * @param OperationDefinition $operation
  *
  * @return ObjectType
  *
  * @throws \Exception
  */
 protected static function getOperationRootType(Schema $schema, OperationDefinition $operation)
 {
     switch ($operation->get('operation')) {
         case 'query':
             return $schema->getQueryType();
         case 'mutation':
             $mutationType = $schema->getMutationType();
             if (!$mutationType) {
                 throw new \Exception('Schema is not configured for mutations.');
             }
             return $mutationType;
     }
     throw new \Exception('Can only execute queries and mutations.');
 }