dangerous-fuchsiaD
Refine2y ago
7 replies
dangerous-fuchsia

Error trying to create new, graphql

Error: Variable "$author" of required type "AddAuthorInput!" was not provided.: {"response":{"errors":[{"message":"Variable "$author" of required type "AddAuthorInput!" was not provided.","locations":[{"line":1,"column":20}],"extensions":{"code":"BAD_USER_INPUT","stacktrace":["GraphQLError: Variable "$author" of required type "AddAuthorInput!" was not provided."," at coerceVariableValues

this is my create.tsx

import { useForm, Create } from "@refinedev/antd";
import { Form, Input } from "antd";
import { ADD_AUTHOR } from "./queries";

export const CreateAuthor = () => {
const { formProps, saveButtonProps, onFinish } = useForm({
redirect: "edit",
meta: {
gqlMutation: ADD_AUTHOR,
},
onMutationError(error, data) {
console.log(error, data);
},
});

const handleSubmit = async (values: any) => {
try {
await onFinish({ author: { name: values.name } } );
} catch (error) {
console.error("Error adding author:", error);
}
};

return (
<Create saveButtonProps={saveButtonProps} >
<Form {...formProps} onFinish={handleSubmit} layout="vertical">
<Form.Item label="Name" name="name">
<Input />
</Form.Item>
</Form>
</Create>
);
};

interface AddAuthorResponse {
author: {
name: string;
};
}

and this is my

import gql from "graphql-tag";

export const AUTHORS_LIST_QUERY = gql query Authors { authors { id name } } ;

export const AUTHOR_SHOW_QUERY = gql query AuthorShow($id: ID!) { author(id: $id) { name } } ;

export const ADD_AUTHOR = gql mutation AddAuthor($author: AddAuthorInput!) { addAuthor(author: $author) { name } } ;

any ideas or suggestions?
Was this page helpful?