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()); }
/** * This method looks up the field on the given type defintion. * It has special casing for the two introspection fields, __schema * and __typename. __typename is special because it can always be * queried as a field, even in situations where no other fields * are allowed, like on a Union. __schema could get automatically * added to the query type, but that would require mutating type * definitions, which would cause issues. * * @param Schema $schema * @param ObjectType $parent * @param Field $ast * * @return FieldDefinition */ protected static function getFieldDefinition(Schema $schema, ObjectType $parent, Field $ast) { $name = $ast->get('name')->get('value'); $schemaMeta = Introspection::schemaMetaFieldDefinition(); $typeMeta = Introspection::typeMetaFieldDefinition(); $typeNameMeta = Introspection::typeNameMetaFieldDefinition(); if ($name === $schemaMeta->getName() && $schema->getQueryType() === $parent) { return $schemaMeta; } else { if ($name === $typeMeta->getName() && $schema->getQueryType() === $parent) { return $typeMeta; } else { if ($name === $typeNameMeta->getName()) { return $typeNameMeta; } } } $tmp = $parent->getFields(); return isset($tmp[$name]) ? $tmp[$name] : NULL; }