ember-cli-mirage-graphql
ember-cli-mirage-graphql copied to clipboard
Object support for args, necessary for Prisma Framework
Currently, you can only write Queries that accept string
arguments. You can however write Mutations that accept string
or object
arguments. So it seems natural to assume that Queries would support object
arguments as well.
Although I think this is a useful gap to fill regardless of the use case, I do have a use case that makes this a critical addition for me. I'm using Prisma Framework (formerly Prisma 2) to generate a CRUD API with a GraphQL endpoint. The GraphQL schema generated by Prisma Framework looks like this:
type Person {
id: ID!
address: Address!
age: Int!
firstName: String!
lastName: String!
pets(name: String): [Pet!]!
createdAt: Date!
}
input PersonWhereUniqueInput {
id: ID
}
type Query {
person(where: PersonWhereUniqueInput!): Person
...
}
Because this schema is generated automatically, it would be impractical for me to change this schema.
So my Queries look like this:
query($id: ID!) {
person(where: {
id: $id
}) {
id
address {
line1
line2
city
state
zip
}
age
firstName
lastName
pets {
age
name
weight
}
createdAt
}
}
Now that I have added support for object arguments in Queries, all that I have to do is add where
to the argsMap
for each model in my app. You can see what that looks like for the dummy app in this commit: 1ad530f
Tests
I wrote 4 new acceptance tests for this. I also had to add new routes and controllers to serve as examples for how the equivalent Queries and Mutations for People would be done with Prisma. My naming adds the word "Prisma" in a few places in the dummy app. I'm open to suggestions here. I figured that since the use case is so specific, I might as well be clear about where it came from.