Closed todda00 closed 5 years ago
The good news is this works using mocks at least. The mock resolver fields can access arguments, and return different results as needed.
cy.mockGraphql({
schema: Cypress.env("GRAPHQL_SCHEMA"),
endpoint: "/api",
mocks: {
RootQuery: () => ({
me: () => ({
__typename: "User",
_id: "user_1",
firstName: "Test",
lastName: "User",
shortName: "Test U.",
hasPerm: (parent, args)=> {
// logic to check arguments and return what is needed
return true;
}
})
})
}
}).as("mockGraphqlOps");
Sorry for the noise, this method works as well for operations, for a while the alias name was tripping me up until I realized this is all the same as a resolver function, alias or not.
cy.mockGraphqlOps({
operations: {
ChannelsQuery: {
me: {
...me,
hasPerm: (parent, args)=> {
// logic to check arguments and return what is needed
return true;
}
},
...
}
}
});
I have some queries which call the same field with different arguments and use an alias to remap the field names for the duplicate fields in the query. This behavior is not possible to replicate in
cy.mockGraphqlOps({operations: {...}})
.See a potential query here:
if I provide the operation value:
This will set
canCreateChannels
andcanViewChannels
both as false, but there is no way to set the alias values individually.