Reputation: 151
My project is built with vue.js and severless framework, when I try to integrate it with Aws AppSync and Amplify (by using amplify cli), it auto generated a schema.json under /src/graphql
which is almost unreadable. So every time I want to change the schema i go to the appsync console, change it there, then I do one of the following:
execute amplify api update
in terminal so that it updates whatever has been change in the cloud and update my local schema accordingly.
download the schema.json file from the appsync console after the change. going back and forth is very consuming.
So my question is:
Can I somehow use schema.graphql in my project instead of the unreadable schema.json
I also noticed if I comment out every line in schema.json or even removed the schema.json completely in /src/graphql, it does not give me any error when i run it, why is this happening?
Thanks in advance.
Upvotes: 2
Views: 3404
Reputation: 13
Ex. (one to many relation) The single user will have more posts
type User @model {
id: ID!
name: String
posts: [Post] @connection(keyName: "postsByUser", fields: ["id"])
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
}
type Post @model
@key(name: "postsByUser", fields: ["userID"]) {
id: ID!
description: String!
userID: ID!
user: User @connection(fields: ["userID"])
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
}
Then save & check this schema model is having any error by run the following command and it will throw error if anything is wrong
amplify api gql-compile
After checking give amplify push and it will change the schema, data sources, queries & dynamodb tables.
To update/generate schema.json, queries & other files in frontend use the following command
amplify add codegen bbp3andl********** (->appsync id)
Refer this link to write schema model https://blog.grandstack.io/graphql-api-configuration-with-neo4j-graphql-js-bf7a1331c793
Upvotes: 0
Reputation: 31
This question is a little old, but it might help someone:
The schema.json
file is the introspection schema [1]. It's designed to be machine-readable so your favourite library can help you validate your requests client-side, it's certainly not designed to be human-readable or editable.
Instead you should edit amplify/backend/api/<apiname>/schema.graphql
. When you then amplify api push
it will do the following:
schemaPath
in .graphqlconfig.yml
, which is your src/graphql
directory by default.[1] https://graphql.org/learn/introspection/
[2] https://docs.amplify.aws/cli/graphql-transformer/directives
Upvotes: 3
Reputation: 1280
I don't have much experience with Amplify, but I have used AppSync with Serverless. I maintain the schema (using the cleaner SDL format) under version control in the repo, and a CI script uploads to S3, then update AppSync via Cloudformation (embedded in serverless.yml).
The AWS::AppSync::GraphQLSchema resource allows for an inline schema (not so clean) or a pull down from S3. Having a separate file also enables you to test locally and better track changes/drift.
Upvotes: 0