-
Notifications
You must be signed in to change notification settings - Fork 0
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: Custom type and ref arg handling in SchemaProcessor with tests #412
feat: Custom type and ref arg handling in SchemaProcessor with tests #412
Conversation
|
- Update schema processor to correctly include all custom types - Adjust test cases in CustomOperations.test.ts, client-schema.ts, and ssr-req-client.ts - Update corresponding snapshots to reflect change
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'm seeing some unexpected changes in the code and tests/snapshots, as called out in the comments.
Let's baseline on the requirements. When custom query/mutation arguments
contain non-scalar values (e.g., custom types or a refs to custom types), we should:
- Define a GraphQL Input type from the arguments in the SDL output from
schema.transform()
- Reference this input type in the query/mutation field argument
- The GraphQL Type definition for the custom type should remain in the SDL output
For example, given:
Location: a.customType({
lat: a.float(),
long: a.float(),
}),
addLocationToPost: a
.mutation()
.arguments({ postId: a.string(), location: a.ref('Location') })
.handler(a.handler.custom({ entry: './source.js' }))
.returns(a.boolean())
The GraphQL output should be:
type Location
{
lat: Float
long: Float
}
input AddLocationToPostLocationInput
{
lat: Float
long: Float
}
type Mutation {
addLocationToPost(postId: string, location: AddLocationToPostLocationInput): Boolean
}
However, when I pull down the PR and run schema.transform()
on the same schema , I get the following output:
type Location
{
lat: Float
long: Float
}
type Mutation {
addLocationToPost(postId: String, location: ID): Boolean
}
- Input type is not getting generated
addLocationToPost
field arglocation
is referencing typeID
instead of the Input type
After making the requested changes, I recommend linking @aws-amplify/data-schema
into a sample app and actually attempting to deploy some schemas with custom operations containing non-scalar arguments
to make sure everything works as expected.
packages/data-schema/__tests__/__snapshots__/CustomOperations.test.ts.snap
Outdated
Show resolved
Hide resolved
packages/data-schema/__tests__/__snapshots__/CustomOperations.test.ts.snap
Outdated
Show resolved
Hide resolved
packages/data-schema/__tests__/__snapshots__/CustomOperations.test.ts.snap
Outdated
Show resolved
Hide resolved
packages/integration-tests/__tests__/defined-behavior/2-expected-use/custom-operations.ts
Outdated
Show resolved
Hide resolved
...tion-tests/__tests__/defined-behavior/2-expected-use/__snapshots__/custom-operations.ts.snap
Outdated
Show resolved
Hide resolved
const s = a.schema({ | ||
MyQueryReturnType: a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
nestedCustomType: a.customType({ | ||
nestedA: a.string(), | ||
nestedB: a.string(), | ||
grandChild: a.customType({ | ||
grandA: a.string(), | ||
grandB: a.string(), | ||
}), | ||
}), | ||
}), | ||
myQuery: a | ||
.query() | ||
.handler(a.handler.function('myFn')) | ||
.returns( | ||
a.customType({ | ||
fieldA: a.string(), | ||
fieldB: a.integer(), | ||
nestedCustomType: a.customType({ | ||
nestedA: a.string(), | ||
nestedB: a.string(), | ||
grandChild: a.customType({ | ||
grandA: a.string(), | ||
grandB: a.string(), | ||
}), | ||
}), | ||
}), | ||
) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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.
How is the unit test branch coverage of the code we're introducing in this change?
@@ -258,8 +256,7 @@ type Subscription { | |||
`; | |||
|
|||
exports[`CustomOperation transform dynamo schema custom subscriptions Custom subscription where .for() resource has a CustomType return type 1`] = ` | |||
"type CreateCustomTypePostReturnType @aws_api_key | |||
{ | |||
"type CreateCustomTypePostReturnType { |
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.
Here and below, I'm seeing that the auth graphql directives (@aws_api_key
, @aws_cognito_user_pools
, etc.) are now getting dropped from the generated types.
Does this PR actually need to change anything about how return types are handled relative to main
? I could be wrong, but AFAIK, we already support custom types and refs to custom types as the return types for custom queries and mutations.
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.
Thanks for making the requested changes.
Approving merge to the feat branch.
There are a few changes in SchemaProcessor.ts
that I'd like to review more closely, but I will defer that until the feat -> main PR is ready.
3517643
into
feat/allow-customtype-ref-in-arguments
Problem:
-Custom type and ref arguments in custom queries and mutations were not properly handled in the SchemaProcessor, leading to incorrect GraphQL schema generation.
-Several integration tests in custom-operations.ts were previously skipped due to schema validation issues related to custom type argument features.
Related PR
-This PR addresses the skipped tests and completes the implementation started in PR #402.
Changes:
generateInputTypes
function to create GraphQL input types for custom structures.Validation:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.