Skip to content

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

Open
@simstern

Description

@simstern

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions