0

am I setting the schema wrongly? I can mutation & Query in playground, but in the frontend hit this error: "Network error: Unexpected token < in JSON at position 0", then I checked in backend, that shows below message, may anyone help me?

# import * from './generated/prisma.graphql'

    type Mutation{
        createLeague(name: String, zhName: String, image: String, season: String, nation: String, clubs: Club): League!
        createClub(name: String, zhName: String, tla: String, badge: String, leagues: League): Club!

    }

    type Query{
        leagues: [League]!
        clubs: [Club]!
    }
Error: The type of Mutation.createLeague(clubs:) must be Input Type but got: Club.

The type of Mutation.createClub(leagues:) must be Input Type but got: League.
    at assertValidSchema (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/type/validate.js:78:11)
    at Object.validate (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/validation/validate.js:55:35)
    at doRunQuery (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:111:42)
    at /mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:21:56
    at process._tickCallback (internal/process/next_tick.js:68:7)
Error: The type of Mutation.createLeague(clubs:) must be Input Type but got: Club.

The type of Mutation.createClub(leagues:) must be Input Type but got: League.
    at assertValidSchema (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/type/validate.js:78:11)
    at Object.validate (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/graphql/validation/validate.js:55:35)
    at doRunQuery (/mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:111:42)
    at /mnt/c/Users/chisi/coding/tipson0.1/server/node_modules/apollo-server-core/dist/runQuery.js:21:56
    at process._tickCallback (internal/process/next_tick.js:68:7)
nburk
  • 22,409
  • 18
  • 87
  • 132
Perry Chan
  • 11
  • 3
  • 1
    You need to define an Input type for Club and League and pass it to your mutations. like ClubInput & LeageInput more info: https://graphql.org/graphql-js/mutations-and-input-types/ – Matin Kajabadi Jan 21 '19 at 07:24
  • As the error indicates, only input types can be used for arguments, not object types. This is a duplicate. Please see [here](https://stackoverflow.com/questions/54119116), [here](https://stackoverflow.com/questions/46158288), [here](https://stackoverflow.com/questions/52744900) and [here](https://stackoverflow.com/questions/54119116). – Daniel Rearden Jan 21 '19 at 09:26
  • 1
    Possible duplicate of [Apollo / GraphQl - Type must be Input type](https://stackoverflow.com/questions/52744900/apollo-graphql-type-must-be-input-type) – Marco Daniel Jan 21 '19 at 13:55
  • thanks all, I got it, I change the type to input || import all the thing from Prisma and set the argument as same as the generated file, this two solutions both can solve the issue – Perry Chan Jan 22 '19 at 09:19

0 Answers0