Graphql-code-generator: Unable to find any GraphQL type definitions for the following pointers: -"src/**/*.graphql"

Created on 18 Nov 2019  Â·  8Comments  Â·  Source: dotansimha/graphql-code-generator

Describe the bug
I have created a brand new react-native application and I, now, attempt to generate graphql schema from my backend https://__server__url__/graphql where it is exposed.
I entered

$ graphql-codegen init

and followed the steps from the wizard, which produced the below codegen.yml:

overwrite: true
schema: "https://__server__url__/graphql"
documents: "src/**/*.graphql"
generates:
  src/generated/graphql.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"
  ./graphql.schema.json:
    plugins:
      - "introspection"

This is the package.json script I should run to generate the schema:

"schema": "graphql-codegen --config codegen.yml"

But the above command fails with the following errors:

✖src/generated/graphql.tsx
    Error: Unable to find any GraphQL type definitions for the following pointers: -"src/**/*.graphql"

...

✖ ./graphql.schema.json
    Error: Unable to find any GraphQL type definitions for the following pointers: -"src/**/*.graphql"

My backend is a nestjs application which exposes a graphql interface. My schema.gql file has been generated by type-graphql which I paste below

  1. My GraphQL schema:
# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!!   DO NOT MODIFY THIS FILE BY YOURSELF   !!!
# -----------------------------------------------

"""Date custom scalar type"""
scalar Date

type Mutation {
  create_user(user: UserInput!): User!
  create_pofficer(pofficer: POfficerCreateInput!): POfficer!
  create_incident(incident: TIncidentInput!): TIncident!
  add_incident_type(incident_type: TIncidentTypeInput!): TIncidentType!
}

type POfficer {
  _id: ID!
  userid: ID!
  user: User!
}

input POfficerCreateInput {
  name: String!
  surname: String!
  phone: String!
}

type Query {
  users: [User!]!
  pofficers: [POfficer!]!
  incidents: [TIncident!]!
  incident_types: [TIncidentType!]!
}

type TIncident {
  _id: ID!
  createdAt: Date!
  incidenttype_id: ID!
  pofficer_id: ID!
  toffender_id: ID
  toffender_phone: String!
  carnumber: String!
  incident_status: String!
  pofficer: POfficer!
  toffender: User!
  incident_type: TIncidentType!
}

input TIncidentInput {
  incidenttype_id: ID!
  pofficer_id: ID!
  toffender_phone: String!
  carnumber: String!
}

type TIncidentType {
  _id: ID!
  name: String!
  description: String
}

input TIncidentTypeInput {
  name: String!
  description: String
}

type User {
  _id: ID!
  name: String!
  surname: String!
  email: String
  phone: String!
}

input UserInput {
  name: String!
  surname: String!
  email: String!
  phone: String!
}


  1. My GraphQL operations:
# Put your operations here
  1. My codegen.yml config file:
overwrite: true
schema: "https://__server__url__/graphql"
documents: "src/**/*.graphql"
generates:
  src/generated/graphql.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"
  ./graphql.schema.json:
    plugins:
      - "introspection"

Expected behavior
Should generate typescript types from remote schema

Environment:

  • OS: Macbook pro high sierra
  • @graphql-codegen/cli: 1.8.3
  • NodeJS: v12.10.0

Most helpful comment

I have solved the issue by applying the answer from this stackoverflow question here (the question is also from me)
Basically I had to create a .graphql file with at least 1 operation (query or mutation). And now it works. I don't know whether this is the real solution to this problem or a hack. Maybe it should be mentioned in the tutorial.

All 8 comments

Do you have client-side operations on documents: "src/**/*.graphql"?

I have the same problem, operations should be generated from schema right?

No you need to provide the operations against the schema.

I have solved the issue by applying the answer from this stackoverflow question here (the question is also from me)
Basically I had to create a .graphql file with at least 1 operation (query or mutation). And now it works. I don't know whether this is the real solution to this problem or a hack. Maybe it should be mentioned in the tutorial.

Thanks @seyaobey !

I've used amplify-graphql-docs-generator (https://github.com/aws-amplify/amplify-cli/tree/master/packages/amplify-graphql-docs-generator) to generate queries, mutations, etc directly from the type schema.

Is it possible to do this with graqhql-codegen?

@aldegoeij we have an open issue for that: https://github.com/dotansimha/graphql-code-generator/issues/2349

Closing this for now. As mentioned before, either remove typescript-operations and documents: section, or add an actual operation :)

I have the same problem, operations should be generated from schema right?

How to do it

Operations are not generated from the schema. They should be written based on the components / client that needs them.
Generating GraphQL operations isn't different than using REST...

@syedahmedusman2 please refer to: https://github.com/dotansimha/graphql-code-generator/discussions/2349

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  Â·  3Comments

rogerg93 picture rogerg93  Â·  3Comments

fvisticot picture fvisticot  Â·  3Comments

RIP21 picture RIP21  Â·  3Comments

dotansimha picture dotansimha  Â·  3Comments