Problem
I am working on a next.js app with graphql, and I am trying to create content from my app.
When I run my mutation query I get this:
Error: Mutation failed due to permission errors: {"response":{"errors":[{"message":"Mutation failed due to permission errors","extensions":{"code":"403","failedActions":[{"action":"create","model":"NousContacter","stage":"DRAFT"}]}}],"data":null,"extensions":{"requestId":"cl47gsed70qm30bt92jr1df04"},"status":403,"headers":{"map":{"cache-control":"private, no-store","content-type":"application/json"}}},"request":{"query":"\n\tmutation CreateNousContacter($nom: String!, $email: String!, $message: String! ) {\n\t\tcreateNousContacter(data: {nom: $nom, email: $email, message: $message}){id}}","variables":{"nom":"TESTname","email":"TESTmail","message":"TESTmessage"}}}
My get queries are all working without any problem, but it's the first mutation I write and I don't know how to get it to work.
My request
import { request, gql } from 'graphql-request';
const graphqlAPI = process.env.NEXT_PUBLIC_GRAPHCMS_ENDPOINT;
export const nousContacter = async ({ nom, email, message }) => {
const query = gql`
mutation CreateNousContacter($nom: String!, $email: String!, $message: String!){
createNousContacter(data: {nom: $nom, email: $email, message: $message}) {
id
}
}`;
await request(graphqlAPI, query, {nom, email, message});
};
On the graphics side, all the fields of my model are read/write
BONUS QUESTIONS
1- Whenever I get my mutation to work, how can I create my content and put it in directly in the published stage? I haven't managed to do it in the API playground of graphics
2- Can I do what I want to do, with my field on read only?