-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(api-graphql): custom operation selection set on nested custom types #13078
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
2 changes: 1 addition & 1 deletion
2
packages/api-graphql/__tests__/internals/utils/generateEnumsProperty.test.ts
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ import { | |
flattenItems, | ||
authModeParams, | ||
getCustomHeaders, | ||
generateSelectionSet, | ||
selectionSetIRToString, | ||
defaultSelectionSetForNonModelWithIR, | ||
} from '../APIClient'; | ||
import { | ||
AuthModeParams, | ||
|
@@ -197,27 +200,6 @@ function innerArguments(operation: CustomOperation): string { | |
return args.length > 0 ? `(${args})` : ''; | ||
} | ||
|
||
/** | ||
* Accepts a Model or NonModel from generated introspection schema and | ||
* generates the selection set string. | ||
* | ||
* @param nonModel Model or nonModel object from introspection schema. | ||
* @returns String selection set. | ||
*/ | ||
function modelishTypeSelectionSet( | ||
nonModel: SchemaModel | SchemaNonModel, | ||
): string { | ||
return Object.values(nonModel.fields) | ||
.filter( | ||
field => | ||
hasStringField(field, 'type') || | ||
hasStringField(field.type, 'nonModel') || | ||
hasStringField(field.type, 'enum'), | ||
) | ||
.map(field => field.name) | ||
.join(' '); | ||
} | ||
|
||
/** | ||
* Generates the selection set string for a custom operation. This is slightly | ||
* different than the selection set generation for models. If the custom op returns | ||
|
@@ -251,11 +233,12 @@ function operationSelectionSet( | |
) { | ||
return ''; | ||
} else if (hasStringField(operation.type, 'nonModel')) { | ||
const model = modelIntrospection.nonModels[operation.type.nonModel]; | ||
return `{${modelishTypeSelectionSet(model)}}`; | ||
const nonModel = modelIntrospection.nonModels[operation.type.nonModel]; | ||
return `{${selectionSetIRToString( | ||
defaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection), | ||
)}}`; | ||
Comment on lines
+237
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exporting the default function to call it in passed into IRToString function makes me wonder if it would be better to export a function that combines the two functions instead of stacking the calls here. |
||
} else if (hasStringField(operation.type, 'model')) { | ||
const nonModel = modelIntrospection.models[operation.type.model]; | ||
return `{${modelishTypeSelectionSet(nonModel)}}`; | ||
return `{${generateSelectionSet(modelIntrospection, operation.type.model)}}`; | ||
} else { | ||
return ''; | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
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.
We're wrapping strings in surrounding curly brackets,
{}
, in several places. I find the character sequence`{${
a bit hard to read, which makes me wonder if a few extra chars forwrapInCurlyBrackets(x)
might be more readable.Not specific to this PR, but a thing I thought of.