graphql-let icon indicating copy to clipboard operation
graphql-let copied to clipboard

Does graphql-let support multiple schema?

Open Inlustra opened this issue 3 years ago • 3 comments

Bit of an odd request I guess. We're currently building a service using NextJS to create our own GraphQL API, however, our DB is also GraphQL driven.

Does graphql-let support this use case? I'm not really even sure how this would work but I'm curious to see if anyone has some thoughts as I really love the integration Graphql-let provides us within the editor.

Inlustra avatar Dec 10 '20 22:12 Inlustra

Hi @Inlustra, thank you for raising the issue. It's an interesting case. I assume the GraphQL driven DB is something like AWS AppSync.

First, it makes me think "do you really want 2 GraphQL layers?". Of course, you can (and you have to do in some cases), but I'd recommend you to start by using one. In that case, your .graphql-let.yml will look like below. Please note I didn't test, just guessing from AWS docs and a practical config depends on your auth settings.

schema: 
    - https://YOURAPPSYNCENDPOINT/graphql:
          headers:
              Authorization: YOUR-TOKEN-HERE
              Content-Type: application/graphql
              x-api-key: ABC123

Am I guessing correctly?

piglovesyou avatar Dec 11 '20 00:12 piglovesyou

You are I think, however, I would rather keep all of our business logic out of the db graphql layer itself and instead handled by the server.

I've ended up using a mixture of Graphql-codegen and graphql-let and I do realise that this is somewhat of an edge-case but I think it's definitely raised a bug.

graphql-let: (handling frontend <-> server)

schema: '**/*.graphqls'
schemaEntrypoint: 'server/schema/typeDefs/index'
documents: '**/*.client.graphql'
plugins:
  - named-operations-object
  - typescript
  - typescript-operations
  - typescript-react-apollo
cacheDir: __generated__

codegen.yml (handling server <-> db)

schema: ${DB_URL}
documents: "server/**/*.db.graphql"
generates:
  server/db/types.ts:
    - typescript
  server/:
    preset: near-operation-file
    presetConfig:
      extension: .graphql.ts
      baseTypesPath: db/types.ts
    plugins:
      - typed-document-node
      - typescript-operations

This actually works great when running the commands! However the babel config does not seem to be respecting the documents: '**/*.client.graphql' and I've getting errors as it's trying to match my .db.graphql with the schema from the config. Example:

[ graphql-let ] 
    GraphQLDocumentError: Cannot query field "addUser" on type "Mutation".
        at server/schema/resolvers/auth/auth.db.graphql:8:3

I should re-iterate, running: "codegen": "dotenv graphql-let && dotenv graphql-codegen", works correctly. But in dev mode (And therefore through babel/webpack) I hit the errors described above.

I'd love to learn more if this setup is really not advised though

Inlustra avatar Dec 11 '20 01:12 Inlustra

Thank you for describing the detail. It seems related to your Babel config. I'm afraid I can't dig into your project's config but if you give me a minimum reproduction project, I'd love to see it.

piglovesyou avatar Dec 11 '20 04:12 piglovesyou