Missing query & mutation types after compilation for second time #8504
-
Hey everyone. I am not quite sure if this could be a bug or if I am doing something wrong. But I have a few React components that are using the import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
overwrite: true,
errorsOnly: true,
schema: "../api/schema.graphql",
documents: "./src/**/*.{ts,tsx}",
ignoreNoDocuments: true,
generates: {
"./src/__generated__/": {
preset: "client",
plugins: [],
},
},
};
export default config; My generated But unfortunately, a lot of queries got removed from my generated types and now there are only 75 lines. I realized that all the import { graphql } from "~/__generated__";
import {
CreateInvitationMutation,
CreateInvitationMutationVariables,
} from "~/__generated__/graphql";
const CreateInvitationMutation = graphql(`
mutation CreateInvitation($input: CreateInvitationInput!) {
createInvitation(input: $input)
}
`);
function Component() {
// The generics are the generated types that I import. And the ones that will get removed after running the generator again (after making changes to the schema file).
const { mutate, data } = useMutation<CreateInvitationMutation, CreateInvitationMutationVariables>(CreateInvitationMutation)
} I have no clue what's going on and I tried to run the generation script with the
I have no idea what's going on and I hope someone is able to help me out. Thanks a lot. Edit: I have created a gist to show the differences between the initial types and the types that got removed after the second time of generating. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @gino, The import { graphql } from "~/__generated__";
const CreateInvitationMutation = graphql(`
mutation CreateInvitation($input: CreateInvitationInput!) {
createInvitation(input: $input)
}
`);
function Component() {
const { mutate, data } = useMutation(CreateInvitationMutation)
} |
Beta Was this translation helpful? Give feedback.
Hi @gino,
The
client-preset
removes the need to provide the Generic type arguments to GraphQL client'suseQuery()
/useMutation()
functions.You can directly use it as showcased below and still get full type safety: