graphql-schema-linter
graphql-schema-linter copied to clipboard
Fields beginning with a single Underscore are not linted properly
Currently, if a field begins with a single underscore, no matter how it is written, the linter does not think it is camel cased:
The field `Object._timeStamp` is not camel cased. fields-are-camel-cased
after removing the underscore the error disappears.
Per the graphql specification, the only issue with underscores is if there are two underscores prefixing a field:
Per the spec, the only mention of underscores are the idea that somevar
and some_var
are different, and:
Types and fields required by the GraphQL introspection system that are used in the same context as user‐defined types and fields are prefixed with "__" two underscores. This in order to avoid naming collisions with user‐defined GraphQL types. Conversely, GraphQL type system authors must not define any types, fields, arguments, or any other type system artifact with two leading underscores.
So this should be a valid naming convention.
Thanks for opening this issue @reskin89! 😄
That's an interesting one. Out of curiosity, in your case, what's the meaning behind prefixing fields with a _
?
Ultimately in my situation is for ordering purposes. Generally fields that begin with underscores come in at the top of the alphabetical order, so a few fields I deemed to be most important and wanted them to appear at the top of the schema, as well as the first in a full JSON object on return of an API call.
Thanks for the clarification! 😄
I agree with you that prefixing with a single _
is technically valid according to the spec.
Since this is the first time this comes up, my gut feeling is that most people don't do this though. Changing FieldsAreCamelCased
(that has been around for ~2 years) to accept _
prefixes feels like something that might not be desirable for everyone.
Some of these rules are about personal preference so I realize it might not please everyone.
One way of upstreaming a fix for this would be to add support for options to rules. That way we could set the default behaviour of FieldsAreCamelCased
to be reject_underscore_prefixes: true
and allow users like yourself to override that with reject_underscore_prefixes: true
in their config.
This might be a bit involved as a change though. If you want a quicker solution, you could omit this rule when running the linter and copy/paste it in your project so that you can adapt it as you wish.
Hope that helps!