Skip to content
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

Impossible to access cookies within mutateAndGetPayload #115

Closed
Blackening999 opened this issue May 17, 2018 · 1 comment
Closed

Impossible to access cookies within mutateAndGetPayload #115

Blackening999 opened this issue May 17, 2018 · 1 comment

Comments

@Blackening999
Copy link

Blackening999 commented May 17, 2018

Hello here

At first glance this library looks nice, unless you start working with it and end up stack with poor documentation. I have a very simple and very common use case. I want to handle auth. through session and by having LoginMutation I need to access ctx inside it so I can:

  1. set cookies
  2. access ctx.* objects

Without such information - it's completely useless.

Right now I've tried to set cookies on 2nd and 3rd argument. Nothing works.
Attempted to pass values through rootValue - same.
It's literally impossible to use that library when everything in Koa is running around ctx

It's either me not understanding something or my case is super rare

server.js

router.all(
  '/graphql',
  graphqlHTTP((request, ctx) => ({
    schema: graphqlSchema,
    graphiql: true,
    rootValue: { ctx },
    pretty: true,
  })),
)

LoginMutation.js

  mutateAndGetPayload: async ({ email, password }, ctx) => {
    ctx.cookies.set('mykEY', '123')
    console.log(`ctx.cookies.set: ${ctx.cookies.get('mykEY')}`) //nothing
}

When I do that inside middleware - it works!

server.js

app.user(mymw)

mymw.js

export default async function sessionMiddleware(ctx, next) {
  console.log(`ctx.cookies.set: ${ctx.cookies.get('mykEY')}`)
  ctx.cookies.set('mykEY', '123') // here

//2nd call and it's there

@Blackening999
Copy link
Author

OMG... that was a mistake from my side

JakeChampion/fetch#386
credentials: ‘same-origin’,

That's awful....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant