graphql-js: GraphQLSchema does not completely validate names
The validateName function that is used to validate lots of schema parts is currently only checking that names are not reserved:
https://github.com/graphql/graphql-js/blob/6b253e7159a6a6c64c05bcc6bb863fef5a42eeb7/src/type/validate.ts#L206-L217
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.~ (Not the case, see below)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 19 (11 by maintainers)
We still haven’t worked out exactly how the default environment is set up. We wanted the default to be production, see further discussion in #4426
Yes, that’s what I meant. Sure it would still incur some overhead (the config property creation and the
ifcondition evaluation) per entity, but in terms of DX this seems like the nicest approach - in cases where you don’t construct the schema entity-by-entity, but load a pre-validated config or parse a schema document, it should be rather simple to passassumeValidName(s): trueinto the constructor call of each class.At least one motivation for doing validation separately within
validateSchema()is that if we know the entire schema is valid, including the names, we can skip the call tovalidateSchema(), and schema construction will be faster.On the other hand, you mention the tension, that there is a benefit in fast-failing for common developer errors where the call to
validateSchema()may happen at runtime (or potentially in some integration test step, but still late vis a vis the individual developer). And you suggest a boundary in terms of computational complexity: we should validate individual arguments to constructors for GraphQL Schema Elements in terms of correctness within constructors, whereas Schema Element interaction across the schema with its greater complexity should be deferred tovalidateSchema().I see the tension, but find myself falling on the other side of it => I want schema construction at runtime to be as fast as possible. If it were up to me, I would vote for moving this validation back out of the constructor.