-
-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GraphQL] Add support for mutations #565
Comments
Could you elaborate a bit on why this isn't possible? I'm not too familiar with GraphQL terms, but a quick look at the GraphQL structure suggests that you should be able to do this with appropriate values to It is definitely the case that our GraphQL support could be improved, though. |
The GraphQL documentation has the following example:
This suggests that it would be appropriate to use If this doesn't work for you, it would be helpful to include the error messages you are getting, and ideally a modified version of the graphQL example that reproduces the problem. |
@TimothyJones if I use withQuery for mutation im getting error like "no interaction found on POST" this is my pseudo code setup for mutation const client = new ApolloClient({
cache: new InMemoryCache({
addTypename: false
}),
link: createHttpLink({
fetch: require('node-fetch'),
headers: {
'content-type': 'application/json'
},
uri: 'http://localhost:4012/1746213/v1/',
})
});
export function mutation() {
return client
.mutate({
mutation: GQLTag(setTest)
}).then((result: any) => result.data);
} and this is my pseudo code setup for spec const provider = new Pact({
port: 4012,
log: path.resolve(process.cwd(), 'logs', 'set-test-integration.log'),
spec: 2,
dir: path.resolve(process.cwd(), 'pacts/set-test'),
consumer: 'test-panel',
provider: 'test-api'
});
test.before('setting up graphql', async () => {
await provider.setup();
});
test('Deal', async (t: any) => {
t.plan(1);
const graphqlMutation = new GraphQLInteraction()
.withQuery(setTest)
.uponReceiving('test')
.withOperation('setTest')
.withVariables({})
.withRequest({
path: '/1746213/v1/',
method: 'POST',
})
.willRespondWith({
status: 200,
headers: {
'Content-Type': 'application/json',
},
body: {
data: like(data)
}
});
await provider.addInteraction(graphqlMutation);
const response = await mutation();
t.deepEqual(response.data, data.data);
});
test.afterEach(async (t: any) => {
await t.notThrowsAsync(provider.verify());
});
test.after('pact.js mock server graceful shutdown', async () => {
await provider.finalize();
});
|
Would you be able to provide the exact error from the log please? Also, could you include the full test file (in your example, the definition of setTest is missing).
If you can’t share your code for proprietary reasons, a modified copy of the graphql example would work too.
|
@TimothyJones I realized that the error code in the console was confusing because I found information about mismatched strings in the log file. {
"body": {
- "query": "mutation setTest($deal:DASDealInput){dream_adserver{set_deal (deal: $deal){hit{deal_id deal_name}}}}\n"
+ "query": "mutation setTest($deal: DASDealInput) {\n dream_adserver {\n set_deal(deal: $deal) {\n hit {\n deal_id\n deal_name\n }\n }\n }\n}\n"
}
} |
@TimothyJones i solved the problem by using spaces instead tabulators (1tab=2spaces) and by removing spaces between methods and opening brace this is wrong version mutation setTest ($deal: DASDealInput){
dream_adserver {
set_deal (deal: $deal) {
hit {
deal_id
deal_name
}
}
}
} and this is working version mutation setTest($deal: DASDealInput){
dream_adserver {
set_deal(deal: $deal) {
hit {
deal_id
deal_name
}
}
}
} is possible to change matching behavior ???? |
Issue Classification
Feature Request
Currently it's not possible to test mutation. To GraphQLInteraction class should be added "withMutation" method.
The text was updated successfully, but these errors were encountered: