2021年5月5日星期三

Why is the graphql input type breaking the app

I'm having a problem. I tried to test a mutation on an Apollo GraphQL api. It worked when I used the individual fields for the mutation type but when I replaced the fields with the input type I created, I get an error. It's inside a NextJS project, inside the api folder, so I'm using apollo-server-micro. [error message][1]

Working Code

const { gql } = require("apollo-server-micro");    export const typeDefs = gql`    type Appointment {      id: ID!      firstName: String      lastName: String      email: String      phoneNumber: String    }      type Query {      appointments: [Appointment]      appointment(id: Int): Appointment    }      type Mutation {      bookAppointment(        firstName: String!        lastName: String        email: String        phoneNumber: String      ): Appointment    }      input AppointmentInput {      firstName: String!      lastName: String      email: String      phoneNumber: String    }  `;    const { gql } = require("apollo-server-micro");    export const typeDefs = gql`    type Appointment {      id: ID!      firstName: String      lastName: String      email: String      phoneNumber: String    }      type Query {      appointments: [Appointment]      appointment(id: Int): Appointment    }      type Mutation {      bookAppointment(appointment: AppointmentInput): Appointment    }      input AppointmentInput {      firstName: String!      lastName: String      email: String      phoneNumber: String    }  `;  

Problem Code

const { gql } = require("apollo-server-micro");    export const typeDefs = gql`    type Appointment {      id: ID!      firstName: String      lastName: String      email: String      phoneNumber: String    }      type Query {      appointments: [Appointment]      appointment(id: Int): Appointment    }      type Mutation {      bookAppointment(appointment: AppointmentInput): Appointment    }      input AppointmentInput {      firstName: String!      lastName: String      email: String      phoneNumber: String    }  `;  
https://stackoverflow.com/questions/67411701/why-is-the-graphql-input-type-breaking-the-app May 06, 2021 at 12:05PM

没有评论:

发表评论