prisma / p1-to-p2-upgrade-path-feedback

4 stars 1 forks source link

Sending GraphQL queries with Prisma Client #11

Open nikolasburk opened 4 years ago

nikolasburk commented 4 years ago

This question was asked by a community member and I'm relaying it here myself so others can see how to deal with these situations.


With prisma-binding it was also possible to fetch arbitrary data (full graphql query) and also have mutations with multiple operations.

Let's say I have an operation where I supply an ID but the type of the model related to the ID might differ:

query QueryAnimal($id: ID!) {
  node(id: $id) {
    id
    ... on Dog {
      leashcolor
    }
    ... on Cat {
      woolcolor
    }
  }
}

Or fetch different types based on the same variable:

query QueryAnimals($id: [ID!]!) {
    cats(where: {id_in: $ids}) {
        name
        favoriteFood
    }
    dogs(where: {id_in: $ids}) {
        name
        leashcolor
    }
    lamas(where: {id_in: $ids}) {
        cuteness
    }
}

With Prisma1 I can just use client.request(query) to fetch this data. How would I do that with Prisma2?