Переменная '$ _data' не может быть типом ввода в мутации GraphQL с Prisma - PullRequest
0 голосов
/ 30 апреля 2018

Я использую Prisma с GraphQL и получаю ошибки при запуске мутации. Я успешно развернул prisma и связал его с локальным graphQL.

- datamodel.graphql - настройка призмы

type Link {
  id: ID! @unique
  description: String!
  url: String!
  postedBy: User
}

type User {
  id: ID! @unique
  name: String!
  email: String! @unique
  password: String!
  links: [Link!]!
}

- schema.graphql - локальная настройка

# import Link from "./generated/prisma.graphql"
type Query {
  info: String!
  feed: [Link!]!
}

type Mutation {
  post(url: String!, description: String!): Link!
  signup(email: String!, password: String!, name: String!): AuthPayload
  login(email: String!, password: String!): AuthPayload
}

type AuthPayload {
  token: String
  user: User
}

type User {
  id: ID!
  name: String!
  email: String!
  links: [Link!]!
}

Резольвер для регистрации мутации

async function signup(parent, args, context, info) {
  // 1
  const password = await bcrypt.hash(args.password, 10)
  // 2
  const user = await context.db.mutation.createUser({
    data: { ...args, password },
  }, `{ id }`)

  // 3
  const token = jwt.sign({ userId: user.id }, APP_SECRET)

  // 4
  return {
    token,
    user,
  }
}

И это содержание .graphqlconfig.yml

projects:
  app:
    schemaPath: src/schema.graphql
    extensions:
      endpoints:
        default: http://localhost:4000
  database:
    schemaPath: src/generated/prisma.graphql
    extensions:
      prisma: database/prisma.yml

Запускаю GraphQL-запрос, который я запускаю.

mutation {
  signup(
    name: "Alice"
    email: "alice@graph.cool"
    password: "graphql"
  ) {
    token
    user {
      id
    }
  }
}

И ответ, который я получил, когда я бегу, это

{
  "data": {
    "signup": null
  },
  "errors": [
    {
      "message": "Variable '$_data' cannot be non input type 'UserCreateInput!'. (line 1, column 19):\nmutation ($_data: UserCreateInput!) {\n                  ^",
      "locations": [],
      "path": [
        "createUser"
      ]
    }
  ]
}

Я не могу найти причину этого.

Спасибо.

Ответы [ 3 ]

0 голосов
/ 06 июля 2018

Исправлено, если перейти на правую конечную точку в index.js

const server = new GraphQLServer({
   typeDefs: './src/schema.graphql',
   resolvers,
   context: req => ({
       ...req,
       db: new Prisma({
           typeDefs: 'src/generated/prisma.graphql',
           endpoint: 'http://localhost:4466/local/dev',
           secret: 'secret',
           debug: true,
       }),
   }),
})
0 голосов
/ 30 мая 2019

Попробуйте использовать prisma deploy --force

Это сработало для меня.

0 голосов
/ 28 июня 2018

Я думаю, что ваш prisma.yml был не прав.

# The endpoint represents the HTTP endpoint for your Prisma API. It encodes
# several pieces of information:
# * Prisma server (`localhost:4466` in this example)
# * Service name (`myservice` in this example)
# * Stage (`dev` in this example)
# NOTE: When service name and stage are set to `default`, they can be omitted.
# Meaning http://myserver.com/default/default can be written as http://myserver.com.
endpoint: http://localhost:4466/myservice/dev
...