graphql / graphql-spec

GraphQL is a query language and execution engine tied to any backend service.
https://spec.graphql.org
14.31k stars 1.13k forks source link

Support non-list variables for list arguments #1043

Open Shane32 opened 1 year ago

Shane32 commented 1 year ago

See this feature request:

netlify[bot] commented 1 year ago

Deploy Preview for graphql-spec-draft ready!

Name Link
Latest commit 3dfc15c21d78534309165dba0bffe5e5215a6729
Latest deploy log https://app.netlify.com/sites/graphql-spec-draft/deploys/64ee5a0232c6af000800db13
Deploy Preview https://deploy-preview-1043--graphql-spec-draft.netlify.app/draft
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Shane32 commented 1 year ago

Example stepping through logic for AreTypesCompatible with new steps when comparing list-type locations with non-list type variables:

Step Scenario 1 Scenario 2 Scenario 3 Scenario 4 Scenario 5
variableType String String! String String! String
locationType [String!] [String!] [String] [String] [String]!
1 Is locationType is non-null type false false false false true
1a If variableType is NOT a non-null type true - return false
2 if variableType is a non-null type false true false true
2a let nullableVariableType... String String
2b AreTypesCompatible String, [String!] String, [String]
3 if locationType is a list type true true
3a let itemLocationType String! String
3b If variableType is NOT a list type true true
3b1 If itemLocationType is a non-null type true false
3b1a Let nullableItemLocationType... String
3b1b AreTypesCompatible String, String
3b2 AreTypesCompatible String, String
Shane32 commented 1 year ago

Note that no rules have changed for how default values for variables work. Since all existing nullability checks apply to the outermost layer, all are still valid with these new rules, in line with 'option 5' outlined in #1033.

Shane32 commented 1 year ago

GraphQL.NET's implementation of this is here, locked behind an experimental option flag:

benjie commented 1 year ago

If you haven't already, please consider adding this to an upcoming GraphQL Working Group. Let me know if you need any guidance.

https://github.com/graphql/graphql-wg/tree/main/agendas/2023

benjie commented 1 year ago

Oops, just saw https://github.com/graphql/graphql-spec/issues/1033#issuecomment-1763566528

benjie commented 1 year ago

I think we'd wrap all of that above in its own algorithm, something like:

  1. Let {value} be {CoerceVariableValue(variableName, argumentType)}.
benjie commented 1 year ago

Before working any more on this, I recommend that we land:

I then have edits in mind that I think would make this a clearer win.