I've been trying to find some documentation on this on the Prisma websites but to be honest it's a bit difficult to find very detailed use cases there, especially when the problem is as difficult to describe as this one is.
I have the situation where my front end sends a mutation request to createPosting
on my GraphQL-Yoga server with the fields positionTitle, employmentType, description, requirements, customId, expiresAt
(I have thoroughly tested that this works as expected). I want to add a createdAt
field before creating the node on the Prisma service.
In my GraphQL-Yoga server I have a datamodel.graphql that includes the following:
type Posting {
id: ID! @unique
customId: String! @unique
offeredBy: Employer!
postingTitle: String!
positionTitle: String!
employmentType: EmploymentType!
status: PostingStatus!
description: String
requirements: String
applications: [Application!]!
createdAt: DateTime!
expiresAt: DateTime!
}
My schema.graphql has this under Mutations:
createPosting(postingTitle: String!,
positionTitle: String!,
employmentType: String!,
description: String!,
requirements: String!,
customId: String!,
expiresAt: DateTime!,
status: PostingStatus): Posting!
Finally in my createPosting resolver I attempt to mutate the Prisma backend like this:
const result = await context.prisma.mutation.createPosting({
data: {
offeredBy: { connect: { name: context.req.name} },
postingTitle: args.postingTitle,
positionTitle: args.positionTitle,
employmentType: args.employmentType,
description: args.description,
requirements: args.requirements,
customId: args.customId,
createdAt: new Date().toISOString(),
expiresAt: expiresAt,
status: args.status || 'UPCOMING'
}
})
When I try to run this from my front-end I get the following error on the server:
Error: Variable '$_v0_data' expected value of type 'PostingCreateInput!' but got: {"customId":"dwa","postingTitle":"da","positionTitle":"da","employmentType":"PART_TIME","status":"UPCOMING","description":"dada","requirements":"dadada","expiresAt":"2018-09-27T00:00:00.000Z","createdAt":"2018-09-04T20:29:10.745Z","offeredBy":{"connect":{"name":"NSB"}}}. Reason: 'createdAt' Field 'createdAt' is not defined in the input type 'PostingCreateInput'.
From this error message I would assume that my Prisma service for some reason does not know about createdAt, as I recently added this field, but when I inspect the type Posting and the PostingCreateInput in the GraphQL playground on the Prisma host I find the field createdAt! in both those places.
I tried deleting the generated prisma.graphql and deploying again for a fresh file but that did not work. And when I inspected prisma.graphql, PostingCreateInput did indeed miss the createdAt field, even though the Prisma server seems to have it.
If anyone can point me in the right direction as to what is wrong, or give me a better idea of how to set up variables that should be stored in the database but created in my Yoga-server as opposed to in front-end I would be very appreciative :)
Although this question might seem a bit specific I believe the idea of creating data for the fields during on the server should be possible before creating nodes, but at the moment I'm struggling with wrapping my head around how to do it.
TLDR; Want to create a createdAt:DateTime
field on my GraphQL-Yoga server on a resolver before sending a create request to my Prisma service.