Skip to content

KnownTypeNames validation fails for fragments with variables (experimentalFragmentVariables option) #1706

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
simstern opened this issue May 28, 2025 · 1 comment

Comments

@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.

@simstern
Copy link
Author

Sorry, I was about to open a PR which fixes this problem. Closing this one in favour of #1707

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

No branches or pull requests

1 participant