Error: GraphQL error: field "company_id" not found in type: 'teams_insert_input'
See original GitHub issueThe 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:
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:
- Created 4 years ago
- Comments:10
@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
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.