apollographql / apollo-rs

Spec compliant GraphQL Tools in Rust.
Apache License 2.0
566 stars 45 forks source link

Names must not start with two underscores `__` #743

Open qwerdenkerXD opened 10 months ago

qwerdenkerXD commented 10 months ago

Description

The Specification declares the following:

# Reserved Names
Any Name within a GraphQL type system must not start with two underscores "__"
unless it is part of the introspection system as defined by this specification.

Currently, this is not satisfied by apollo-compiler@1.0.0-beta.6 and has been forgotten in PR #713

Steps to reproduce

Validate the following schema which has some of such invalid names defined:

type Query {
  __field(__arg: __MyScalar!): __MyType!
}

type __MyType {}

interface __MyInterface {}

scalar __MyScalar

enum __MyEnum {
  __EnumValue
}

union __MyUnion = __MyType | __Schema

input __MyInput {
  __field: __MyScalar!
}

Here a code sample.

Expected result

The validation should fail and have some respective diagnostics.

Actual result

The validation succeeds.

Environment

goto-bus-stop commented 10 months ago

Name also represents introspection names, so it's intentional that it supports underscores. We should handle this in validation, though!

SimonSapin commented 9 months ago

~I think we could check this either:~

~I have a mild preference for the lexer, since that’s where we check other aspects of Name syntax~

SimonSapin commented 9 months ago

I wrote the above with the incorrect assumption that every single Name anywhere in a document would need checking. The spec phrasing isn’t great but I think the spirit of it is about definitions that introduce a new named thing in a type system. So yes, checking in Schema::validation makes more sense.

qwerdenkerXD commented 9 months ago

spec-ref sounds like everything to me. So including it in executables is also necessary. But I agree to check only for definitions, as you aren't able to refer to such definitions anyway if you can't define them.

SimonSapin commented 9 months ago

The reserved name bit of spec does say "Any Name within a GraphQL type system" though. Type system being a schema. :thinking:

qwerdenkerXD commented 9 months ago

oh, my bad, you're right.