Apollo GraphQL: Can't connect to schema via Yarn

I’m running the docker standalone version:

docker run -it -p 9000:8080 -p 9080:9080 --rm -v /Users/paul/Share/development/dgraph/data:/dgraph --name dgraph dgraph/standalone:latest

I’m going through the message board tutorial and setting up apollo:

https://dgraph.io/learn/courses/messageboardapp/react/develop/react/graphql-queries/

My codegen.yml:

overwrite: true
schema: "http://localhost:9000/admin/schema"
documents:
  - "app/**/*.graphql"
generates:
  app/types/graphql.ts:
    plugins:
      - typescript
  app/:
    preset: near-operation-file
    presetConfig:
      baseTypesPath: types/graphql
      folder: types
      extension: .ts
    plugins:
      - typescript-operations
      - typescript-react-apollo
      - named-operations-object
    config:
      reactApolloVersion: 3
      withHOC: false
      withHooks: true
      withComponent: false

I’ve tried every possible combination of port/endpoint I have found combing the docs, posts and examples.

The error:

✔ Parse configuration
  ❯ Generate outputs
    ❯ Generate app/types/graphql.ts
      ✖ Load GraphQL schemas
        → Failed to load schema
        Load GraphQL documents
        Generate
    ❯ Generate to app/ (using EXPERIMENTAL preset "near-operation-file")
      ✖ Load GraphQL schemas
        → Failed to load schema
        Load GraphQL documents
        Generate


 Found 2 errors

  ✖ app/
    Failed to load schema from http://localhost:9000/admin/schema:

        Unexpected token < in JSON at position 0
        SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)

If someone can point me in the direct direction. Would appreciate it.

Thanks

You need to introspect the schema from the graphql endpoint not the admin/schema endpoint.

Like:

schema: "http://localhost:9000/graphql

Again, appreciate the reply.

From my initial post:

I’ve tried every possible combination of port/endpoint I have found combing the docs, posts and examples.

I have tried that already. Attaching screenshot:

Totally my bad! I already had a process running on 9000. Totally forgot about it. :crazy_face:

Once I moved dgraph to 4000. Now it’s fine.

But how it was able to still serve requests is funny!

1 Like