I have an error in my application. I use Next.js / ApolloClient / GraphQL and Prisma. The error concerns the GraphQL schema and it's use in Mutation
:
Error : Reason: 'end_date' Field 'end_date' is not defined in the input type ArticleCreateInput
I tried to copy/paste the global schema on each file to have the good corresponding data, but it doesn't work.
My data Model (datamodel.prisma):
type Article {
id: ID! @id
title: String!
description: String!
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
image: String
maxUserNumber: Int!
greatImage: String
street: String!
begin_date: DateTime!
end_date: DateTime!
price: Int!
user: User!
}
My schema.graphql:
createArticle(
title: String!
description: String!
image: String
maxUserNumber: Int!
greatImage: String
street: String!
begin_date: DateTime!
end_date: DateTime!
price: Int!
): Article!
In my Genertated file (prisma.graphql):
input ArticleCreateInput {
id: ID
title: String!
description: String!
image: String
maxUserNumber: Int
greatImage: String
street: String
begin_date: DateTime
end_date: DateTime
price: Int!
user: UserCreateOneInput!
}
ClientSide Mutation and State:
const CREATE_ARTICLE_MUTATION = gql`
mutation CREATE_ARTICLE_MUTATION(
$title: String!
$description: String!
$image: String
$maxUserNumber: Int!
$greatImage: String
$street: String!
$begin_date: DateTime!
$end_date: DateTime!
$price: Int!
) {
createArticle(
title: $title
description: $description
image: $image
maxUserNumber: $maxUserNumber
greatImage: $greatImage
street: $street
begin_date: $begin_date
end_date: $end_date
price: $price
) {
id
}
}
`;
export class CreateArticle extends Component {
state = {
adresse: "",
title: "",
description: "",
image: "",
greatImage: "",
price: 0,
nbPersons: 2,
loadigImg: false,
begin_date: moment(new Date(Date.now())).format("YYYY-MM-DD"),
end_date: moment(new Date(Date.now()))
.add(1, "days")
.format("YYYY-MM-DD")
};
With the Mutation call:
<Mutation
mutation={CREATE_ARTICLE_MUTATION}
variables={{
...this.state,
maxUserNumber: this.state.nbPersons,
street: this.state.adresse
}}
>
And the backendMutation:
async createArticle(parent, args, ctx, info) {
if (!ctx.request.userId) {
throw new Error("Vous devez être connecté");
}
const article = await ctx.db.mutation.createArticle(
{
data: {
user: {
connect: {
id: ctx.request.userId
}
},
...args
}
},
info
);
return article;
},
When I use my createArticle mutation I have an error that specified:
Reason 'end_date' field is not defined in the type ArticleCreateInput
But, when I log the args on my mutation, I have all my fields!