-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): allow referencing derived types in schema customization #34787
Conversation
…le instead of graphql-js
\\"\\"\\"This is description too\\"\\"\\" | ||
withoutDefault: String | ||
usingDerivedType: BarChildSortInput | ||
): String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all snapshot changes are additive - I expanded tests to include more cases
… iteration, only apply it if field or ancestor has args
@@ -65,6 +65,7 @@ const convert = <TContext = any>({ | |||
const sortFields = {} | |||
|
|||
Object.keys(fields).forEach(fieldName => { | |||
let deprecationReason = parentFieldDeprecationReason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github doesn't show full picture in the diff by default as rest of the code is few lines below but this change is because
gatsby/packages/gatsby/src/schema/types/sort.ts
Lines 67 to 78 in d846f89
Object.keys(fields).forEach(fieldName => { | |
const fieldConfig = fields[fieldName] | |
const sortable = | |
typeComposer instanceof UnionTypeComposer || | |
typeComposer instanceof ScalarTypeComposer | |
? undefined | |
: typeComposer.getFieldExtension(fieldName, `sortable`) | |
if (sortable === SORTABLE_ENUM.NOT_SORTABLE) { | |
return | |
} else if (sortable === SORTABLE_ENUM.DEPRECATED_SORTABLE) { | |
deprecationReason = `Sorting on fields that need arguments to resolve is deprecated.` | |
} |
In particular on line 77 once a field is marked as deprecated, all the remaining fields in current iteration are also deprecated
For example:
type Foo {
field1: Int # this is fine
field2(arg1: Int): Int # this sets `deprecationReason`
field3: Int # this should be fine, but currently marked as deprecated
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fix #31523 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely, yes - at least comments about fields that don't have arguments but still causing this deprecation to show up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move this to separate PR as this change is not dependend on rest of this PR, I did add it here as this warning was part of "issues" I encountered when working on rest of the changes here. The main problem for me was that Graphiql was not autosuggesting fields due to them being deprecated, but it was still working if I manually typed them in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can stay in imo, I was just curious :)
@@ -177,134 +212,127 @@ const printType = (tc, typeName) => { | |||
return printScalarType(tc) | |||
} else if (tc instanceof InputTypeComposer) { | |||
return printInputObjectType(tc) | |||
} else { | |||
throw new Error(`Did not recognize type of ${typeName}.`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS was complaining, because all possible types in NamedTypeComposer
were handled. Also we never actually passed typeName
to this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some questions around typings
Changes:
graphql-compose
( fix: don't try to instantiate GraphQLType when getting name of named type composer graphql-compose/graphql-compose#373 )graphql-js
types - we do print schema before all "derived types" (such as our various filter and sort inputs etc) are created. This meant we couldn't ever reference such derived types and be able to print schema, because at the time of printing the type doesn't exist yet (causing printing to throw). I did try initially moving printing to after we create derived types but this changed too many things - it started printing everything and then we were getting exceptions that we try to create types reserved for Gatsby -gatsby/packages/gatsby/src/schema/schema.js
Lines 591 to 607 in d846f89
[sc-46064]