Skip to content
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

SDL Validation Prior to Schema Creation #2944

Open
Cito opened this issue Mar 3, 2021 · 2 comments
Open

SDL Validation Prior to Schema Creation #2944

Cito opened this issue Mar 3, 2021 · 2 comments
Milestone

Comments

@Cito
Copy link
Member

Cito commented Mar 3, 2021

Recently the issue was raised for the Python port graphql-core that enum values aren't validated against their defintion when they are used as default arguments SDL. This is the example that was given:

const sdl = `
enum Role {
  ADMIN
  USER
}

type Query {
  hello(r: Role = ADMIN): String
  complex(i: Test = { role: DOES_NOT_EXIST }): String
  complexAlt(i: Test): String
}

input Test {
  ignore: String
  role: Role = INVALID
}
`

const schema = graphql.buildASTSchema(graphql.parse(sdl))

const fields = schema.getType('Query').getFields()
const arg1 = fields.hello.args[0]
const arg2 = fields.complex.args[0]

console.log(arg1, arg2)

Should schema validation not show this is an error?

@saihaj
Copy link
Member

saihaj commented Mar 3, 2021

I guess schema validation should throw an error.

GraphQL services must return one of the defined set of possible values. If a reasonable coercion is not possible they must raise a field error
GraphQL enum result

In this case role doesn’t choose from one of the possible defined types in the set which means it should raise an error.

CC: @IvanGoncharov

@IvanGoncharov IvanGoncharov added this to the post-16.0.0 milestone Mar 31, 2021
@yaacovCR
Copy link
Contributor

Keeping this open despite #3814 because it would be nice if this could be validated within the SDL.

@yaacovCR yaacovCR changed the title Default values that are enums are not validated SDL Validation Prior to Schema Creation Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants