amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

How do I update src/graphql/schema.json

Open berenddeboer opened this issue 6 years ago • 20 comments

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

berenddeboer avatar Jan 07 '20 03:01 berenddeboer

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

ammarkarachi avatar Jan 09 '20 01:01 ammarkarachi

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 avatar Jan 09 '20 01:01 berenddeboer

@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 avatar Jan 09 '20 19:01 kaustavghosh06

@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.

berenddeboer avatar Jan 10 '20 03:01 berenddeboer

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

berenddeboer avatar Jan 13 '20 01:01 berenddeboer

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 avatar Jan 17 '20 00:01 berenddeboer

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

kaustavghosh06 avatar Feb 13 '20 22:02 kaustavghosh06

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

kaustavghosh06 avatar Feb 19 '20 17:02 kaustavghosh06

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?

mayteio avatar Mar 26 '20 01:03 mayteio

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

mayteio avatar Mar 26 '20 01:03 mayteio

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

arlyon avatar May 12 '20 16:05 arlyon

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.

alexofob avatar May 16 '20 05:05 alexofob

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.

jonperryxlm avatar Jun 09 '20 15:06 jonperryxlm

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!

dandalf avatar Jul 15 '20 20:07 dandalf

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.

willmruzek avatar Jul 17 '20 17:07 willmruzek

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.

ianmartorell avatar Aug 05 '20 09:08 ianmartorell

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

willmruzek avatar Aug 05 '20 19:08 willmruzek

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

My graphQL backend was created in another project, I just wanted to connect to the back-end and utilize it inside my client react app. Hence, I just needed the graphQL schema pulled and code to be generated.

I first ran this from @mayteio. Thanks a lot!!!! The api_id is retrieved from appsync under settings. Notice that I am using schema.json instead of src/graphql/schema.json

aws appsync get-introspection-schema --api-id=xxx --format=JSON schema.json --profile=xxx

then while at the root folder (parent of src for my react project), I ran these two commands

amplify codegen types # this generated src/API.ts
amplify codegen statements # this generated the 3 files (mutations.graphql, queries.graphql, subscriptions.graphql) under src/graphql 

It worked.

bilgrami avatar Dec 27 '20 06:12 bilgrami

We are using schema.json, now codegen no longer generates schema.json which means our app might break. Good job.

aprilmintacpineda avatar Feb 18 '21 09:02 aprilmintacpineda

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 03:05 github-actions[bot]