0

OK so I have the following types, with the "Spot" type coming from prisma.

type Query {
  SpotDetails(id: ID!, lat: String, long: String, regLocation: String): SpotDetails!
  Spots: [Spot!]!
}

type SpotDetails {
  info: Spot!
  regulations: [SpotRegulation]

}

type SpotRegulation {
  regulationNumber: String
  generalRegText: String
  waters: String
  seasons: String
  bags: String
  notes: String
}

How do I create the resolver where I can query Prisma for a spot by id and then combine it with the other fields from the SpotRegulation type? Basically I want to be able to query SpotDetails.

Right now for the resolver I have the following, but I do not think it is working because the info provided to the Prisma query is the SpotDetails info and not the Spot info that it is expecting.

SpotDetails(parent, args, ctx, info) {
  let { id } = args;
  let details = new Object();
  details['info'] = ctx.db.query.spot({ where: { id } }, info);

},

Here is the query I'm using on graphQL playground to test this

query {
  SpotDetails(id:"cjkbwq1nm00310a958udjcr20"){
    regulations{
      notes
    }
  }
}
Seldon Stone
  • 474
  • 1
  • 5
  • 16

2 Answers2

0

So I originally included info because that was used in the example code from GraphQL boilerplate. However after looking at the prisma documents in regards to reading data none of the examples included passing the info. I'm not sure what the info is used for but when I removed it from the spots call in the resolver as shown below it worked as expected. I'll still need to figure out why info was passed but for what I needed to accomplish it was needed.

SpotDetails(parent, args, ctx, info) {
  let { id } = args;
  let details = new Object();
  details['info'] = ctx.db.query.spot({ where: { id } });
  return details;
},
Seldon Stone
  • 474
  • 1
  • 5
  • 16
0

If not passed the info object, I think it will not work when nested multi level fields. prisma only return the Spot related fields.

Does Spot has many SpotRegulation ? if so, regulations be sub field of spot ?

If you don't need pass info object, you can use generated javascript client, not prisma-binding db

Gabriel Tong
  • 206
  • 3
  • 12