Amplify-cli: How do I update src/graphql/schema.json

Created on 7 Jan 2020  路  17Comments  路  Source: aws-amplify/amplify-cli

Which Category is your question related to?

Updating src/graphql/schema.json.

None of the commands I've seen such as amplify push do that, and older commands like amplify code generate --download no longer work.

Amplify CLI Version

4.11.0.

What AWS Services are you utilizing?

AppSync + Aurora.

My .graphconfig (regenerated with latest):

projects:
  TestAPI:
    schemaPath: amplify/backend/api/TestAPI/build/schema.graphql
    includes:
      - src/graphql/**/*.js
    excludes:
      - ./amplify/**
    extensions:
      amplify:
        codeGenTarget: javascript
        generatedFileName: ''
        docsFilePath: src/graphql
        region: eu-west-1
        apiId: null
        maxDepth: 2
extensions:
  amplify:
    version: 3
code-gen pending-triage

Most helpful comment

So at some point the schemaPath in .graphqlconfig.yml got changed from /src/graphql/schema.json to a path in the amplify/backend/api folder, probably by a command of the Amplify CLI, because this started happening to me yesterday.

Changing it back to /src/graphql/schema.json makes it so that amplify push and amplify codegen generate schema.json again.

All 17 comments

@berenddeboer amplify push should compile your schema file also amplify api gql-compile will also compile the schema after a change

Well, I wouldn't ask for help if amplify push did this right? Just install the latest, do rm src/graphql/schema.json and let me know if that regenerates it. Not since 4.9.0 on my system.

Same for amplify api gql-compile. Doesn't do a thing.

@berenddeboer The introspection schema - schema.json is not needed anymore for codegen. Previously we were using it for codegen of your mutations, queries and subscriptions. Are you seeing any discrepancy with the code generated?

@kaustavghosh06 I use it with react-admin, so it doesn't have to download the schema first by introspection, i.e. cutting down on startup speed.

@kaustavghosh06 have figured this one out: if you don't have a schema.graphql but use the schema subdirectory, schema.json is not regenerated.

Sorry @kaustavghosh06 why is this closed? Is it fixed? I still really like the ability to regenerate the schema.json, it's just a problem it does this inconsistently, i.e. only in the most basic case.

@berenddeboer Would it be possible for you to use the schema directly for you react-admin app?

Closing due to lack of response. Please comment on this thread if you're stuck on this issue.

Can we please re-open this? I too use it for react-admin and it was a handy inclusion to have. This is a regression. Can I help in any way to add this functionality back in?

In the meantime @berenddeboer, I managed to download it using:

$ aws appsync get-introspection-schema --api-id=xxx --format=JSON src/graphql/schema.json --profile=xxx

I'd've thought that the schema.json _is_ codegen. It's of critical importance to other tooling as the raw schema.graphql does not reflect the API (namely due to the generated queries on the server-side for models).

Going to have a dig and see if I can expose a command to generate it.

edit @alexofob this is the exact workflow I was trying to solve

I would also need the schema.json for apollo config in VScode to benefit from the intellisense support for graphql code.
Without it you have to hack.

Why on earth is this closed? The schema.json file is no longer generated which makes our tooling break. We generate usable enums from the schema, which now don't work. We only noticed this after updating an enum and it wasn't reflected in our build code. This is a bug, no doubt about it. You can't just remove something and not publicise it.

There's a way to fix this using directions found in AppSync in the AWS Console. After your api is pushed, goto your deployed api on AppSync instead of Amplify. On the Getting Started page, follow the directions in the "Integrate with your app" section. Now you have a non-blank API.ts file!

The schema.json is useful for tools like eslint + eslint-plugin-graphql. Would be nice to have schema.json updated on each GQL-related push.

So at some point the schemaPath in .graphqlconfig.yml got changed from /src/graphql/schema.json to a path in the amplify/backend/api folder, probably by a command of the Amplify CLI, because this started happening to me yesterday.

Changing it back to /src/graphql/schema.json makes it so that amplify push and amplify codegen generate schema.json again.

Great catch, @ianmartorell! Your solution worked for me as well. Thanks!

Was this page helpful?
0 / 5 - 0 ratings