Skip to content

Fix known type names validation for fragments with experimental variables #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simstern
Copy link

This fixes building a schema with experimentalFragmentVariables.

Currenty, the DocumentValidator returns Unknown type "String".

Example:

$typeDefs = '
            type Hello {
                world(phrase: String): String
            }
            fragment hello($phrase: String = "world") on Hello {
                world(phrase: $phrase)
            }
            type RootQuery {
                hello: Hello
            }
            schema {
                query: RootQuery
            }
        ';

$astDocument = Parser::parse($typeDefs, ['experimentalFragmentVariables' => true]);

return BuildSchema::buildAST($astDocument);

Fragments should also implement TypeSystemDefinitionNode to have the type names validated against the Type::BUILT_IN_TYPE_NAMES by the GraphQL\Validator\Rules\KnownTypeNames rule:

$isSDL = $definitionNode instanceof TypeSystemDefinitionNode || $definitionNode instanceof TypeSystemExtensionNode;
if ($isSDL && in_array($typeName, Type::BUILT_IN_TYPE_NAMES, true)) {
    return;
}

Sorry, i struggled to add a test for this case with the current mock data in the KnownTypeNamesTest. Please advise if it is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant