-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation of Unions types and Enum values #2675
Comments
@Cito It was a deliberate decision to support empty types during the construction phase so you can write: union SomeUnion
extend union SomeUnion = Foo | Bar so goes for all other types. let schema: GraphQLSchema = buildSchema(`
union SomeUnion
type Query {
union: SomeUnion
}
`);
schema = extendSchema(`
extend union SomeUnion = Foo | Bar
`);
const finalizedSchema: GraphQLFinalizedSchema = assertFinalizedSchema(schema),
const result = graphql({
schema: finalizedSchema,
source: '{ __typename } ',
}); So basically make What do you think about this idea? |
@IvanGoncharov Out of curiosity, what's the use case behind allowing "empty" types like this in the first place? If the intent behind type system extensions is to empower clients to extend remote schemas, an empty union or a composite type with no fields would never exist in that context -- any types exposed by the server would have to already be valid per the spec. So the only time you would do something like the above example would be server-side when constructing the initial schema. Since it's not necessary to use
What am I missing here? |
@IvanGoncharov Right, I understand the idea to postpone the validation until the schema is "finished". But currently, as far as I see that validation never happens, not even when the schema is executed. It also does not answer my first question why the Regarding the |
@danielrearden Nope, you can't execute introspection query against the incomplete schema.
Yes, exactly.
Technically, yes. In practice, it creates a bunch of issues starting from error messages that will show invalid error locations (bet that can be a workaround with More importantly, it prevents more complex scenarios where you combine SDL-first and code first. const sdlSchema = buildSchema(`
input SomeVeryLongInputType {
# ...
}
`);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
foo: {
type: GraphQLString
args: {
arg: { type: sdlSchema.getType('SomeVeryLongInputType') }
},
},
},
}),
}); So in this example, |
@Cito It's done here: graphql-js/src/execution/execute.js Line 277 in 7ee63b0
graphql-js/src/type/validate.js Line 450 in 7ee63b0
If you mean in AST it's the situation with all arrays in AST and track in #2203 probably we will make a breaking change in
It' simply not obvious and create confusion about what functions accept finalized schema and what functions can work with intermediate one. Returning back to your answer
So it's really not obvious that |
@IvanGoncharov - you're right, somehow I totally overlooked that. And yes, #2203 answers the other question. So as for me, this issue can be closed. Maybe you want to open a new one for the question whether the status of schemas and which status the functions expect can be made more obvious. Btw, this is a bit similar to how you need to discern "well-formed" and "valid" XML documents. |
@Cito Great, thanks for XML example 👍 BTW. What do you think about this code? Lines 178 to 181 in 1e1d75e
I think it strange to return schema validation errors to the API clients so it's a second reason why I want to force users to do this check after they built the entire schema but before running the server. What do you think? |
Totally agree. |
In the context of GraphQL-Core, the following questions came up:
types
property ofUnionTypeDefinitionNode
marked as optional? The methodparseUnionMemberTypes()
, which is used to set the property, always returns an array, which may be empty if there are no types specified, but never returns null or undefined.I see that this is not really validated or enforced anywhere in GraphQL.js though. There is only a devAssert in
defineTypes()
that makes sure the types are passed as array and the corresponding testrejects a Union type with incorrectly typed types
.Shouldn't GraphQL.js enfore the full type validation according to the specs in a schema validation rule?
values
ofEnumType
.The text was updated successfully, but these errors were encountered: