0

I'm fairly new to Next.js and frond-end development itself. I am trying to use graphql-codegen to produce types in GraphQl, but somehow I get type error. I immitate the public document, but cannot solve the error. The code is below:

import { FormEvent, useState } from 'react'
import { useMutation } from '@apollo/react-hooks';
import { graphql } from '@src/graphql/generated/gql';

import {
    CreateUserByEmailMutation,
    CreateUserByEmailDocument,
    CreateUserByEmailMutationVariables,
    CreateByEmailInput
} from '@src/graphql/generated/graphql';

const CREATE_USER = graphql(/* GraphQL */ `
    mutation createUserByEmail($input: CreateByEmailInput!) {
        createUserByEmail(input: $input) {
            age
            appleId
            country
            description
            email
            facebookId
            googleId
            id
        }
    }
`);

export const LoginForm = () => {
    const [email, setEmail] = useState<string>('')
    const [password, setPassword] = useState<string>('')
    const input: CreateByEmailInput = {
        email,
        password,
    };
    const [createUser, { loading, error, data }] = useMutation(CREATE_USER, {variables: {input: {email, password}: CreateByEmailInput}});

The error happens at the final row useMutation(CREATE_USER, {variables: {input: {email, password}: CreateByEmailInput}});. If I try const [createUser, { loading, error, data }] = useMutation<CreateUserByEmailMutation, CreateUserByEmailMutationVariables>(CREATE_USER, {variables: {input: {email, password}: CreateByEmailInput}});, still get error. The error message is Argument type {variables: {input: {password: string, email: string}}} is not assignable to parameter type MutationHookOptions<CreateUserByEmailMutation, CreateUserByEmailMutationVariables, DefaultContext, ApolloCache<any>> | undefined .

What should I do?

Best, Kazuya

Kazuya Tomita
  • 667
  • 14
  • 34

0 Answers0