简体   繁体   中英

How to reference generated Prisma schema in my schema.graphql file for a query that filters by id

Trying to add a Query that filters by the unique Id of this object.

Query.js

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

This is also defined in my schema.graphql file.

getAbility(where: AbilityWhereUniqueInput) : Ability

I recognize that AbilityWhereUniqueInput comes from the schema generation done with the Prisma CLI however I am unsure how to reference it for the schema.graphql file.

I have attempted to add this at the top of the file:

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

But whenever I try to run the application, it is saying that it encounters an unexpected character '.', referring to the first part of the file path i'm providing for the import.

Other Relevant Declarations:

schema.graphql

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

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

Here you see I'm generating two files. One for prisma client and other for importing types in 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!
}

See this line

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

Now I can use PostUpdateInput in schema.graphql Make sure that you changes the path following yours.

确保导入的生成模式为.graphql扩展名,因为您不能在graphql文件中导入非graphql文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM