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
Fix context issue in custom GraphQL query and mutation #5532
Conversation
@iicdii Hi, Can you please fix the DCO check. |
Signed-off-by: harimkims <harimkims@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks !
@iicdii The tests are breaking with your changes. |
@alexandrebodin I'll check the code. |
Signed-off-by: harimkims <harimkims@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #5532 +/- ##
==========================================
- Coverage 17.51% 17.50% -0.01%
==========================================
Files 700 700
Lines 10330 10332 +2
Branches 1687 1688 +1
==========================================
Hits 1809 1809
- Misses 7089 7090 +1
- Partials 1432 1433 +1
Continue to review full report at Codecov.
|
Tests look to be passing now good catch @iicdii |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change feels like a patch rather than a clean fix to me.
I would like to know why graphqlCtx.context = ctx
doesn't work and fix it instead of just patching on element of the context then another one etc
@alexandrebodin // packages/strapi-plugin-users-permissions/test/graphql.test.e2e.js`
test('createUser is authorized for admins', async () => {
const res = await authReq({
url: '/graphql',
method: 'POST',
body: {
query: /* GraphQL */ `
mutation {
createUser(
input: {
data: {
username: "test"
email: "test@strapi.io"
password: "test"
}
}
) {
user {
id
username
}
}
}
`,
},
});
expect(res.statusCode).toBe(201);
expect(res.body).toMatchObject({
data: {
createUser: {
user: {
id: expect.anything(),
username: 'test',
},
},
},
});
data.user = res.body.data.createUser.user;
});
|
ctx is the context of the koa app and graphqlContext is the context inside of graphql. When we receive a graphql query it calls koa middleware hence the need to passe the ctx to them. We just clone it to avoid pbl when running multiple queries at once. if you look at the createUser mutation you will see it calls a controller with the context and inside of this you have a ctx.created() call. this is supposed to do ctx.status = 201 and ctx.body = data But this is not copied back to the koa context. Which in my opinion isn't a big deal. I think we should set graphqlContext.context =. ctx and just change the test to check for a 200 status. In graphql other status don't really make sense anyway. |
Signed-off-by: harimkims <harimkims@gmail.com>
Thank you for detailed explanation. I made PR again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks you for this PR 💯 |
Description of what you did:
Fix #5531 issue. Make
policiesMiddleware
works in custom resolvers too.