graphql-php icon indicating copy to clipboard operation
graphql-php copied to clipboard

KnownTypeNames validation fails for fragments with variables (experimentalFragmentVariables option)

Open simstern opened this issue 8 months ago • 1 comments

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 avatar May 28 '25 12:05 simstern

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

simstern avatar May 28 '25 12:05 simstern