Skip to content

Commit

Permalink
chore: adopt "anonymous" vs "unnamed" GraphQL operations term
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Sep 17, 2021
1 parent 9bb4f11 commit c9c92f2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
19 changes: 9 additions & 10 deletions src/handlers/GraphQLHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ const LOGIN = `
}
}
`
const UNNAMED_QUERY = `
query {
unnamedQuery {
query
variables
}
}
`

describe('info', () => {
test('exposes request handler information for query', () => {
Expand Down Expand Up @@ -306,10 +298,17 @@ describe('predicate', () => {
)
})

test('respects graphql.operation endpoint', () => {
test('allows anonymous GraphQL opertaions when using "all" expected operation type', () => {
const handler = new GraphQLHandler('all', new RegExp('.*'), '*', resolver)
const request = createPostGraphQLRequest({
query: UNNAMED_QUERY,
query: `
query {
anonymousQuery {
query
variables
}
}
`,
})

expect(handler.predicate(request, handler.parse(request))).toBe(true)
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/GraphQLHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class GraphQLHandler<
if (!parsedResult.operationName && this.info.operationType !== 'all') {
const publicUrl = getPublicUrlFromRequest(request)
devUtils.warn(`\
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": unnamed GraphQL operations are not supported.
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
`)
Expand Down Expand Up @@ -200,7 +200,7 @@ Consider naming this operation or using "graphql.operation" request handler to i
const statusColor = getStatusCodeColor(response.status)
const requestInfo = parsedRequest?.operationName
? `${parsedRequest?.operationType} ${parsedRequest?.operationName}`
: `unnamed ${parsedRequest?.operationType}`
: `anonymous ${parsedRequest?.operationType}`

console.groupCollapsed(
devUtils.formatMessage('%s %s (%c%s%c)'),
Expand Down
4 changes: 2 additions & 2 deletions test/graphql-api/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('sends a mocked response to a GraphQL mutation', async () => {
})
})

test('prints a warning when captured an unnamed GraphQL mutation', async () => {
test('prints a warning when captured an anonymous GraphQL mutation', async () => {
const runtime = await createRuntime()

const res = await executeGraphQLQuery(runtime.page, {
Expand All @@ -54,7 +54,7 @@ test('prints a warning when captured an unnamed GraphQL mutation', async () => {
expect.arrayContaining([
expect.stringContaining(
`\
[MSW] Failed to intercept a GraphQL request at "POST ${GRAPHQL_TEST_URL}": unnamed GraphQL operations are not supported.
[MSW] Failed to intercept a GraphQL request at "POST ${GRAPHQL_TEST_URL}": anonymous GraphQL operations are not supported.
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
`,
Expand Down
12 changes: 6 additions & 6 deletions test/graphql-api/operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ test('intercepts and mocks a GraphQL query', async () => {
)
})

test('intercepts and mocks an unnamed GraphQL query', async () => {
test('intercepts and mocks an anonymous GraphQL query', async () => {
const runtime = await createRuntime()
const UNNAMED_QUERY = gql`
const ANONYMOUS_QUERY = gql`
query {
unnamedQuery {
anonymousQuery {
query
variables
}
}
`

const res = await executeGraphQLQuery(runtime.page, {
query: UNNAMED_QUERY,
query: ANONYMOUS_QUERY,
variables: {
id: 'abc-123',
},
Expand All @@ -79,7 +79,7 @@ test('intercepts and mocks an unnamed GraphQL query', async () => {
const body = await res.json()
expect(body).toEqual({
data: {
query: UNNAMED_QUERY,
query: ANONYMOUS_QUERY,
variables: {
id: 'abc-123',
},
Expand All @@ -88,7 +88,7 @@ test('intercepts and mocks an unnamed GraphQL query', async () => {

expect(runtime.consoleSpy.get('startGroupCollapsed')).toEqual(
expect.arrayContaining([
expect.stringMatching(/\[MSW\] \d{2}:\d{2}:\d{2} unnamed query 200 OK/),
expect.stringMatching(/\[MSW\] \d{2}:\d{2}:\d{2} anonymous query 200 OK/),
]),
)
})
Expand Down
4 changes: 2 additions & 2 deletions test/graphql-api/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test('mocks a GraphQL query issued with a POST request', async () => {
})
})

test('prints a warning when captured an unnamed GraphQL query', async () => {
test('prints a warning when captured an anonymous GraphQL query', async () => {
const runtime = await createRuntime()

const res = await executeGraphQLQuery(runtime.page, {
Expand All @@ -91,7 +91,7 @@ test('prints a warning when captured an unnamed GraphQL query', async () => {
expect.arrayContaining([
expect.stringContaining(
`\
[MSW] Failed to intercept a GraphQL request at "POST ${GRAPHQL_TEST_URL}": unnamed GraphQL operations are not supported.
[MSW] Failed to intercept a GraphQL request at "POST ${GRAPHQL_TEST_URL}": anonymous GraphQL operations are not supported.
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
`,
Expand Down

0 comments on commit c9c92f2

Please sign in to comment.