Как ссылаться на сгенерированную схему Prisma в моем файле schema.graphql для запроса, который фильтруется по идентификатору

Попытка добавить запрос, фильтрующий по уникальному идентификатору этого объекта.

Query.js

async function getAbility (root, args, context, info) {
        return await context.prisma.ability({
        where : {id : args.abilityId}
    }, info)
}

Это также определено в моем файле schema.graphql.

getAbility(where: AbilityWhereUniqueInput) : Ability

Я понимаю, что AbilityWhereUniqueInput исходит из генерации схемы, выполненной с помощью Prisma CLI, однако я не уверен, как ссылаться на нее для файла schema.graphql.

Я попытался добавить это вверху файла:

# import * from './generated/prisma-client/prisma-schema'

Но всякий раз, когда я пытаюсь запустить приложение, оно сообщает, что встречает неожиданный символ «.», Имея в виду первую часть пути к файлу, которую я предоставляю для импорта.

Другие соответствующие заявления:

schema.graphql

type Ability {
  id: ID! 
  name: String!
  description: String!
  imagePath: String!
}

person Michael    schedule 24.06.2019    source источник


Ответы (2)


prisma.yml

# Specifies the HTTP endpoint of your Prisma API (deployed to a Prisma Demo server).
endpoint: https://eu1.prisma.sh/public-cookiearm-769/exp-graphql-subscription/dev

# Defines your models, each model is mapped to the database as a table.
datamodel: datamodel.prisma

# Specifies the language and directory for the generated Prisma client.
generate:
  - generator: javascript-client
    output: ../src/generated/prisma-client
  - generator: graphql-schema
    output: ../src/generated/prisma.graphql

# Seed your service with initial data based on `seed.graphql`.
seed:
  import: seed.graphql

# Ensures Prisma client is re-generated after a datamodel change.
hooks:
  post-deploy:
    - prisma generate

# If specified, the `secret` must be used to generate a JWT which is attached
# to the `Authorization` header of HTTP requests made against the Prisma API.
# Info: https://www.prisma.io/docs/prisma-graphql-api/reference/authentication-ghd4/
# secret: mysecret123

Здесь вы видите, что я создаю два файла. Один для клиента prisma, другой для импорта типов в schema.graphql.

schema.graphql

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

type Query {
  feed: [Post!]!
  drafts: [Post!]!
  post(id: ID!): Post
}

type Mutation {
  createDraft(title: String!, content: String): Post
  editPost(id: String!, data: PostUpdateInput!): Post
  deletePost(id: ID!): Post
  publish(id: ID!): Post
}

type Subscription {
  post: Post!
}

type Post {
  id: ID!
  published: Boolean!
  title: String!
  content: String!
}

Смотрите эту строку

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

Теперь я могу использовать PostUpdateInput в schema.graphql. Убедитесь, что вы изменили путь, следующий за вашим.

person Naimur Rahman    schedule 15.09.2019

Убедитесь, что импортированная сгенерированная схема имеет расширение .graphql, потому что вы не можете импортировать файлы, отличные от graphql, в файл graphql.

person Yassine Bridi    schedule 02.07.2019