Hi all, hope someone can help me. Firstly when us...
# orm-help
r
Hi all, hope someone can help me. Firstly when using the info object in my mutations am I right it only returns the information defined in the schema for that Mutation. For example if I have defined a mutation `createEvent`:
createEvent(title: String!, description: String, startDate: DateTime!, locations: [Locations]): Event!
Am I right in saying once I run the actual mutation:
Copy code
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:
Copy code
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 Ross
h
That depends upon the
info
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:
Copy code
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;
r
Thanks for the reply, yes I ended up doing this but wasn't sure if there was a more simple way to implicitly return all data in info.