'I have a graphQL query and wanted to convert it GraphQL Transformer v1 to v2
I was working on an existing project using amplify with GraphQl API.
The query shows issues with @Key as Your GraphQL Schema is using "@key" directive from an older version of the GraphQL Transformer
. Since I am new to graphQL, what should I change to make this work?
Thanks
Error:
✖ An error occurred when pushing the resources to the cloud
🛑 An error occurred during the push operation: Your GraphQL Schema is using "@key" directive from an older version of the GraphQL Transformer. Visit https://docs.amplify.aws/cli/migration/transformer-migration/ to learn how to migrate your GraphQL schema.
Query:
type KeyValuePair {
key: String!
value: String
}
type Template
@model
@auth(rules: [ {allow: owner } ]) {
id: ID!
name: String!
description: String
provision_style: String!
status: String!
params: [KeyValuePair]
resources: [KeyValuePair]
}
type Asset
@model
@auth(rules: [ {allow: owner } ])
@key(name: "categoryTypeIndex", fields: ["category", "type"], queryField: "assetsByCategoryAndType")
@key(name: "categoryNameIndex", fields: ["category", "name"], queryField: "assetsByCategoryAndName")
@key(name: "categoryStatusIndex", fields: ["category", "status"], queryField: "assetsByCategoryAndStatus") {
id: ID!
parent: ID
category: String!
type: String!
name: String!
description: String
status: String
template: String
details: [KeyValuePair]
}
type Contract
@model
@auth(rules: [ {allow: owner } ])
@key(name: "tenantAssetIndex", fields: ["tenantId", "assetId"], queryField: "contractsByTenantAndAsset")
@key(name: "tenantNameIndex", fields: ["tenantId", "name"], queryField: "contractsByTenantAndName")
@key(name: "tenantStatusIndex", fields: ["tenantId", "status"], queryField: "contractsByTenantAndStatus") {
id: ID!
type: String!
tenantId: String!
assetId: String!
name: String!
description: String
status: String
details: [KeyValuePair]
resources: [KeyValuePair]
}
type PlatformEvent
@model
@auth(rules: [ {allow: owner } ])
@key(name: "contractTypeIndex", fields: ["contractId", "type"], queryField: "eventsByContractAndType")
@key(name: "contractSourceIndex", fields: ["contractId", "sourceId"], queryField: "eventsByContractAndSource")
@key(name: "sourceTypeIndex", fields: ["sourceId", "type"], queryField: "eventsBySourceAndType") {
id: ID!
type: String!
contractId: String!
sourceId: String!
content: String!
details: [KeyValuePair]
}
Solution 1:[1]
AWS provides a migration guide: https://docs.amplify.aws/cli/migration/transformer-migration/ but unfortunately they don't specify how to actually set your API to use the new/old version.
If you look in your amplify
folder you will find a cli.json
file, to set your backend to use version 1 of the GraphQLTransformer you simply need to edit the file and set the following two properties:
"features": {
"graphqltransformer": {
...
"useexperimentalpipelinedtransformer": false,
"transformerversion": 1,
...
},
From there you simply amplify push
and assuming you've catered for all of the changes the migration guide describes it will update your endpoint correctly.
EDIT: For those looking to upgrade to V2 instead of downgrading to V1 you will need to set the properties as follows:
"features": {
"graphqltransformer": {
...
"useexperimentalpipelinedtransformer": true,
"transformerversion": 2,
...
},
Solution 2:[2]
This should make your life easy.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Mohamed Mohamed |