Ross O'Brien
08/04/2019, 1:59 PMcreateEvent(title: String!, description: String, startDate: DateTime!, locations: [Locations]): Event!
Am I right in saying once I run the actual mutation:
async createEvent(parent, args, ctx, info) {
const { title, description, locations, startDate } = args;
const { userId } = ctx.request;
const newEvent = await ctx.db.mutation.createEvent(
{
data: {
title,
description,
locations: { create: [...locations] },
startDate,
leader: {
connect: {
id: userId,
},
},
},
},
info
);
return newEvent;
Then newEvent
will only contain the id
, description
, startDate
and Locations
array?
I want to return everything defined in my Event
datamodel as I will be using it in a subscription:
type Event {
id: ID! @Unique @id
leader: User! @relation(name: “UserEvents”)
title: String!
description: String
startDate: DateTime!
attendees: [User] @relation(name: “AttendingEvents”)
locations: [Location] @relation(name: “EventLocations”)
comments: [Comment]
updatedAt: DateTime! @updatedAt
createdAt: DateTime! @createdAt
}
What is the best practice for doing this?
Thanks
RossHarshit
08/05/2019, 5:44 PMinfo
parameter. It will return the field you are send in the mutation from the playground. But you can also ensure some fields using addFragmentToInfo from graphql-bindings:
async createEvent(parent, args, ctx, info) {
const { title, description, locations, startDate } = args;
const { userId } = ctx.request;
const newEvent = await ctx.db.mutation.createEvent(
{
data: {
title,
description,
locations: { create: [...locations] },
startDate,
leader: {
connect: {
id: userId,
},
},
},
},
addFragmentToInfo(`fragment EnsureFields on Event { id name # .. }`,info)
);
return newEvent;
Ross O'Brien
08/06/2019, 10:46 AM