Last active
November 29, 2023 00:07
-
-
Save deeja/50ff900a0780ba8c5afa0785e008be0f to your computer and use it in GitHub Desktop.
Amplify GraphQL -> C# Code Generation using `graphql-codegen`
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
# Taken from https://github.com/dotansimha/graphql-code-generator/discussions/4311 | |
scalar AWSTime | |
scalar AWSDate | |
scalar AWSDateTime | |
scalar AWSTimestamp | |
scalar AWSEmail | |
scalar AWSJSON | |
scalar AWSURL | |
scalar AWSPhone | |
scalar AWSIPAddress | |
scalar BigInt | |
scalar Double | |
directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION | |
# Allows transformer libraries to deprecate directive arguments. | |
directive @deprecated(reason: String!) on INPUT_FIELD_DEFINITION | ENUM | |
directive @aws_auth(cognito_groups: [String!]!) on FIELD_DEFINITION | |
directive @aws_api_key on FIELD_DEFINITION | OBJECT | |
directive @aws_iam on FIELD_DEFINITION | OBJECT | |
directive @aws_oidc on FIELD_DEFINITION | OBJECT | |
directive @aws_cognito_user_pools( | |
cognito_groups: [String!] | |
) on FIELD_DEFINITION | OBJECT |
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
schema: | |
- amplify\backend\api\my_project\build\schema.graphql | |
- amplify_shim.graphql | |
generates: | |
AmplifyGraphQL.cs: | |
config: | |
scalars: | |
AWSDateTime: DateTimeOffset | |
AWSDate: DateOnly | |
AWSEmail: string | |
AWSJSON: string | |
AWSURL: string | |
AWSTimestamp: long | |
plugins: | |
- c-sharp |
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
// Run using `npm install` the first time, then `npm run graphql-codegen` after that. | |
{ | |
"scripts":{ | |
"graphql-codegen": "graphql-codegen" | |
}, | |
"devDependencies": { | |
"@graphql-codegen/c-sharp": "5.0.0", | |
"@graphql-codegen/cli": "5.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hopefully this helps people. Discussion around Amplify GraphQL dotansimha/graphql-code-generator#4311
Issues I had:
Unknown type: "AWSDateTime".
Reason: AWS scalars are not defined in the generated amplify graphql schema. The extra
amplify_shim.graphql
schema helps with this.✖ Cannot use GraphQLScalarType "AWSDate" from another module or realm
Reason: The globally installed
graphql-js
was different from the locally installed one. Adding annpm
run command fixed it.