Skip to content

GraphQLSchema does not completely validate names #4362

Open
@ab-pm

Description

@ab-pm

The validateName function that is used to validate lots of schema parts is currently only checking that names are not reserved:

function validateName(
context: SchemaValidationContext,
node: { readonly name: string; readonly astNode: Maybe<ASTNode> },
): void {
// Ensure names are valid, however introspection types opt out.
if (node.name.startsWith('__')) {
context.reportError(
`Name "${node.name}" must not begin with "__", which is reserved by GraphQL introspection.`,
node.astNode,
);
}
}

It should also check that the name complies with https://spec.graphql.org/October2021/#Name, e.g. by testing against the regex /^(?!__)[A-Za-z_][A-Za-z0-9_]*$/.
Otherwise it's possible to construct schemas (via the constructor, not by parsing) that upon printing would lead to invalid syntax, or fields which could never be queried.

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