Comments (3)
Hey @sebamza17, since this new issue isn't directly related to the original, shall we discuss elsewhere? The Mirage Discord works well for me or you can open another GH issue.
from graphql.
I think you're running into the auto-filtering logic of Mirage GraphQL (see #34).
In this case, you'll want to add a custom resolver.
Something like this:
// app/mirage/server.js
import { createServer } from "miragejs"
import { createGraphQLHandler } from "@miragejs/graphql"
import graphQLSchema from "app/gql/schema.gql"
export function makeServer() {
return createServer({
routes() {
const graphQLHandler = createGraphQLHandler(graphQLSchema, this.schema, {
resolvers: {
Query: {
currentAccount(_obj, args, context) {
let currentAccount; // Fetch current account from the Mirage DB or build it up however you need
let membership = context.mirageSchema.memberships.find(args.membershipId);
let membershipVariant = context.mirageSchema.membershipVariants.find(args.variantId);
return {
...currentAccount,
memberships: [{
...membership,
membershipVariants: [{
...membershipVariant
}],
}],
};
}
}
}
});
this.post("/graphql", graphQLHandler)
}
})
}
Apologies for any typos or incorrect method invocations from Mirage's API. IDK how you want to fetch or create the currentAccount
record so I just left a comment there in the example.
LMK if this helps for now.
from graphql.
@jneurock
Thank you for your answer!
I'm working with @villander on this, but for us, queries are working out of the box; but we're having an issue with mutations
we're adding this to our graphQLHandler
as resolvers to handle a specific mutation we're trying to test
UpdateMembershipInstanceResponse: {
resolveType: () => {
return 'UpdateMembershipInstanceSuccess'
}
}
Mutation: {
updateMembershipInstance: (obj, args, context) => {
const { mirageServer } = context
const { id: membershipInstanceId } = args.input
const membershipInstance = mirageServer.schema.membershipInstances.find(membershipInstanceId)
if (membershipInstance) {
membershipInstance.update(args.input)
}
return mirageGraphQLFieldResolver(...arguments)
}
}
and in our schema
// miragejs/schema.js
...
type MembershipInstance {
...
}
type Mutation {
updateMembershipInstance(input: UpdateMembershipInstanceInput): UpdateMembershipInstanceResponse
}
input UpdateMembershipInstanceInput {
...
}
union UpdateMembershipInstanceResponse = UpdateMembershipInstanceSuccess | Error
type UpdateMembershipInstanceSuccess {
membershipInstance: MembershipInstance
}
type Error {
message: String
}
...
this basically works, it grabs mirage data and updates what we need to update, but as per these docs https://github.com/miragejs/graphql#example-deleting-a-person, this should return mirageGraphQLFieldResolver(...arguments)
, but we're having an issue with (probably) the resolver for UpdateMembershipInstanceResponse
, this is what we're getting
"Abstract type "UpdateMembershipInstanceResponse" must resolve to an Object type at runtime for field "Mutation.updateMembershipInstance". Either the "UpdateMembershipInstanceResponse" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function."
any ideas would be welcome!
from graphql.
Related Issues (20)
- Errors on schema with interfaces HOT 1
- Expose API or hooks for custom resolvers HOT 2
- createGraphQLHandler can't deal with directives HOT 4
- Relationship HOT 3
- Handle Custom scalar type like Date HOT 1
- Missing good examples how to use some features on README HOT 1
- TypeError on `returnType` when returning Union from mutations HOT 3
- Expected Iterable, but did not find one for field HOT 5
- connect ECONNREFUSED 127.0.0.1:4001 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) HOT 3
- Delete mutation example in README is incorrect
- [QUESTION] Does this plugin works for testing? HOT 13
- Mirage: You called server.create(<model_name>) but no model or factory was found HOT 2
- ApolloError: Cannot read property 'type' of undefined HOT 1
- How to respond with a server error? HOT 3
- How can I update an entry in resolver and trigger an update in watchQuery? HOT 1
- When updating data, an error occurs if there is a relationship HOT 1
- Example of own resolvers for query / filter involving Union types HOT 1
- Help Wanted: TypeScript and Priorities HOT 9
- model.hasInverseFor is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql.