question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: GraphQL error: field "company_id" not found in type: 'teams_insert_input'

See original GitHub issue

The query is:

export const ADD_TEAM_QUERY = gql`
  mutation addTeam($name: String!, $description: String, $companyId: uuid!) {
    insert_teams(
      objects: {
        name: $name
        description: $description
        company_id: $companyId
      }
    ) {
      returning {
        id
        name
        description
        created_at
        company_id
      }
    }
  }
`

The error is:

Error: GraphQL error: field “company_id” not found in type: ‘teams_insert_input’ at new ApolloError (bundle.esm.js:76) at Object.next (bundle.esm.js:1274) at notifySubscription (Observable.js:152) at onNotify (Observable.js:196) at SubscriptionObserver.next (Observable.js:248) at bundle.esm.js:1079 at Set.forEach (<anonymous>) at Object.next (bundle.esm.js:1078) at notifySubscription (Observable.js:152) at onNotify (Observable.js:196) at SubscriptionObserver.next (Observable.js:248) at bundle.esm.js:107

But when I use my back-end built-in graphql engine sends the request with the same query, everything works:

image

Script to generate Typescript

  • "schema": "apollo client:download-schema ./src/graphql-schema.json",
  • "types": "apollo client:codegen --includes=./src/queries/*.ts --addTypename --target=typescript"

Generated type:

// ====================================================
// GraphQL mutation operation: addTeam
// ====================================================

export interface addTeam_insert_teams_returning {
  __typename: "teams";
  id: any;
  name: string;
  description: string | null;
  created_at: any;
  company_id: any;
}

export interface addTeam_insert_teams {
  __typename: "teams_mutation_response";
  /**
   * data of the affected rows by the mutation
   */
  returning: addTeam_insert_teams_returning[];
}

export interface addTeam {
  /**
   * insert data into the table: "teams"
   */
  insert_teams: addTeam_insert_teams | null;
}

export interface addTeamVariables {
  name: string;
  description?: string | null;
  companyId: any;
}

Code to send the request:

         client
              .mutate({
                mutation: ADD_TEAM_QUERY,
                variables: {
                  name: values.name,
                  description: values.description,
                  companyId,
                },
                update: updateApolloCacheAfterMutation(GET_TEAMS_QUERY),
              })
              .then(() => {
                onClose()
              })
              .catch((e: Error) => {
                console.log(e)
              })

When did it happen:

Everything worked perfectly until I added this company_id column today to the database table and updated all the GraphQL schema locally. It stops working. I tried, clear the generated folder, and re-generate all the things, but still not work.

apollo.config.js

module.exports = {
  client: {
    service: {
      includes: ['src/queries/*.{ts,tsx,graphql}'],
      name: 'Dev',
      url: 'path-to-my-graphql-endpoint',
      headers: {
        // my headers
      },
    },
  },
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

44reactions
Albert-Gaocommented, Jul 31, 2019

@cortopy Wow, anyone who has trouble on this. xD Yes, I am using Hasura.

The problem is, after updating that Permission (adding a new role) from Hasura GUI, somehow, the Hasura engine will not regenerate the graphQL schema on the serverside, which means, when you call it with the token of the role that you just added, it won’t be there.

Even though you can use it in the Hasura Admin GUI. But you propertyly use the x-hasura-secret way. So, you won’t have this problem, if you use that token, you wil see the same error.

How I solve it:

I ended up removing the role, and added it again… and after that, it works…

@shahidhk

16reactions
ericksonccommented, Mar 27, 2020

Thanks - Also a Hasura user here, and I realized my issue is that i just needed to add the column select permission on a new field I’d recently added.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hasura Error - GraphQL error: field "user_id" not found in type
It looks like a permissions error. In the section called Data, select the corresponding table (project in your case?) and open permissions ...
Read more >
Error handling - Apollo GraphQL Docs
Making errors actionable on the client and server. ... GRAPHQL_VALIDATION_FAILED. The GraphQL operation is not valid against the server's schema.
Read more >
Top GraphQL Errors and How to fix them
Identifying error types will help quickly fix them. Clients can encounter these types of errors while communicating with the GraphQL server.
Read more >
GraphQL Content API - Contentful
Rich Text fields work similarly when calculating complexity but have some special ... If the requested locale does not exist, an UNKNOWN_LOCALE error...
Read more >
GraphQL Error Handling with Union Types - Episode #30
If you've been working with GraphQL, and handling errors, you no doubt have had to do some fuzzy matching on errors to get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found