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

fix(GraphQLHandler): move cookie parsing to parse phase #1957

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/core/handlers/GraphQLHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -188,6 +189,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -215,6 +217,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -243,6 +246,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -272,6 +276,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -300,6 +305,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -327,6 +333,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -355,6 +362,7 @@ describe('parse', () => {
})

expect(await handler.parse({ request })).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down Expand Up @@ -393,6 +401,7 @@ describe('parse', () => {
),
}),
).resolves.toEqual({
cookies: {},
match: {
matches: true,
params: {},
Expand All @@ -418,6 +427,7 @@ describe('parse', () => {
),
}),
).resolves.toEqual({
cookies: {},
match: {
matches: true,
params: {},
Expand Down Expand Up @@ -452,6 +462,7 @@ describe('parse', () => {
),
}),
).resolves.toEqual({
cookies: {},
match: {
matches: false,
params: {},
Expand All @@ -471,6 +482,7 @@ describe('parse', () => {
),
}),
).resolves.toEqual({
cookies: {},
match: {
matches: false,
params: {},
Expand Down Expand Up @@ -499,6 +511,7 @@ describe('parse', () => {
),
}),
).resolves.toEqual({
cookies: {},
match: {
matches: false,
params: {},
Expand All @@ -518,6 +531,7 @@ describe('parse', () => {
),
}),
).resolves.toEqual({
cookies: {},
match: {
matches: false,
params: {},
Expand Down Expand Up @@ -726,6 +740,7 @@ describe('run', () => {

expect(result!.handler).toEqual(handler)
expect(result!.parsedResult).toEqual({
cookies: {},
match: {
matches: true,
params: {
Expand Down
12 changes: 7 additions & 5 deletions src/core/handlers/GraphQLHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {

export type GraphQLRequestParsedResult = {
match: Match
cookies: Record<string, string>
} & (
| ParsedGraphQLRequest<GraphQLVariables>
/**
Expand Down Expand Up @@ -166,20 +167,23 @@ export class GraphQLHandler extends RequestHandler<
* need to parse it since there's no case where we would handle this
*/
const match = matchRequestUrl(new URL(args.request.url), this.endpoint)
const cookies = getAllRequestCookies(args.request)
mattcosta7 marked this conversation as resolved.
Show resolved Hide resolved

if (!match.matches) {
return { match }
return { match, cookies }
}

const parsedResult = await this.parseGraphQLRequestOrGetFromCache(
args.request,
)

if (typeof parsedResult === 'undefined') {
return { match }
return { match, cookies }
}

return {
match,
cookies,
query: parsedResult.query,
operationType: parsedResult.operationType,
operationName: parsedResult.operationName,
Expand Down Expand Up @@ -225,13 +229,11 @@ Consider naming this operation or using "graphql.operation()" request handler to
request: Request
parsedResult: GraphQLRequestParsedResult
}) {
const cookies = getAllRequestCookies(args.request)

return {
query: args.parsedResult.query || '',
operationName: args.parsedResult.operationName || '',
variables: args.parsedResult.variables || {},
cookies,
cookies: args.parsedResult.cookies,
}
}

Expand Down
Loading