Fix issue with recursive input object definitions in SDL#4705
Closed
Fix issue with recursive input object definitions in SDL#4705
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Member
Author
|
Hmmm... no it's not safe because it can lead to unexpected outputs: import { buildSchema, printSchema } from './npmDist/index.mjs';
const sdl = `
type Query {
field(in: A): Int
}
input A {
b: B = {}
label: String = "A"
}
input B {
a: A = {b: null}
tail: String = "B"
}
`;
const schema = buildSchema(sdl);
console.log(printSchema(schema));Produces: type Query {
field(in: A): Int
}
input A {
b: B = {a: {b: null}, tail: "B"}
label: String = "A"
}
input B {
a: A = {b: null}
tail: String = "B"
}I.e. the default value for Worse when you start adding non-nulls things get even weirder: import { buildSchema, printSchema } from './npmDist/index.mjs';
const sdl = `
type Query {
field(in: A): Int
}
input A {
b: B = {}
label: String! = "A"
}
input B {
a: A! = {b: null}
tail: String = "B"
}
`;
const schema = buildSchema(sdl);
console.log(printSchema(schema));produces: type Query {
field(in: A): Int
}
input A {
b: B
label: String! = "A"
}
input B {
a: A!
tail: String = "B"
}The |
Member
Author
|
I think we're better off leaving the behavior as-is and waiting for v17 to fix it - we'll leave the current schema definitions as invalid. (Might be worth turning the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to this, the following would throw "Maximum call stack size exceeded":
The equivalent in native code would not:
This means if you
printSchemaon a valid schema and try to rebuild it from SDL, the rebuild might fail (it will for the above schema). The reason being somewhat related to https://rfcs.graphql.org/rfcs/793/ - in code we treat thedefaultValueas coerced, but in SDL we do the coercion of the default value ourselves, which requires us to know the definition of the types, which requires us to know the default value, which requires us to know the types, which [...infinite recursion...]v17 solves this properly but required a breaking change. To address the issue in v16 I've made it so that the
fields()thunk will not allow recursion (it'll return the currently-being-resolved value instead), and I've written everything except the defaultValue to the being-resolved object first, and finally I follow up with a "apply default value" pass which then adds the default values in.I could not come up with SDL that constructs in the current v16 (i.e. doesn't throw the max depth error) that this would cause a divergence in behavior for, so I think it's safe, but I could do with another pair of eyes.
RangeErrorfor combination of recursive input and default value #3871