Skip to content

Commit bb9905f

Browse files
committed
Format
1 parent d6dc429 commit bb9905f

File tree

2 files changed

+116
-116
lines changed

2 files changed

+116
-116
lines changed

packages/batch-delegate/src/batchDelegateToSchema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { pathToArray, relocatedError } from '@graphql-tools/utils';
12
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
23
import { GraphQLError } from 'graphql';
34
import { getLoader } from './getLoader.js';
45
import { BatchDelegateOptions } from './types.js';
5-
import { pathToArray, relocatedError } from '@graphql-tools/utils';
66

77
export function batchDelegateToSchema<TContext = any, K = any, V = any, C = K>(
88
options: BatchDelegateOptions<TContext, K, V, C>,
@@ -16,12 +16,12 @@ export function batchDelegateToSchema<TContext = any, K = any, V = any, C = K>(
1616
const loader = getLoader(options);
1717
return handleMaybePromise(
1818
() => (Array.isArray(key) ? loader.loadMany(key) : loader.load(key)),
19-
res => res,
20-
error => {
19+
(res) => res,
20+
(error) => {
2121
if (options.info?.path && error instanceof GraphQLError) {
2222
return relocatedError(error, pathToArray(options.info.path));
2323
}
2424
return error;
25-
}
25+
},
2626
);
2727
}
Lines changed: 112 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { GraphQLError, parse } from 'graphql';
21
import { batchDelegateToSchema } from '@graphql-tools/batch-delegate';
32
import { delegateToSchema } from '@graphql-tools/delegate';
3+
import { normalizedExecutor } from '@graphql-tools/executor';
44
import { makeExecutableSchema } from '@graphql-tools/schema';
55
import { stitchSchemas } from '@graphql-tools/stitch';
6+
import { GraphQLError, parse } from 'graphql';
67
import { beforeEach, describe, expect, test, vi } from 'vitest';
7-
import { normalizedExecutor } from '@graphql-tools/executor';
88

99
class NotFoundError extends GraphQLError {
10-
constructor(id: unknown) {
11-
super('Not Found', {
12-
extensions: { id },
13-
})
14-
}
10+
constructor(id: unknown) {
11+
super('Not Found', {
12+
extensions: { id },
13+
});
14+
}
1515
}
1616

1717
describe('preserves error path indices', () => {
18-
const getProperty = vi.fn((id: unknown) => {
19-
return new NotFoundError(id);
20-
});
18+
const getProperty = vi.fn((id: unknown) => {
19+
return new NotFoundError(id);
20+
});
2121

22-
beforeEach(() => {
23-
getProperty.mockClear();
24-
});
22+
beforeEach(() => {
23+
getProperty.mockClear();
24+
});
2525

26-
const subschema = makeExecutableSchema({
27-
typeDefs: /* GraphQL */ `
26+
const subschema = makeExecutableSchema({
27+
typeDefs: /* GraphQL */ `
2828
type Property {
2929
id: ID!
3030
}
@@ -40,28 +40,28 @@ describe('preserves error path indices', () => {
4040
propertiesByIds(ids: [ID!]!): [Property]!
4141
}
4242
`,
43-
resolvers: {
44-
Query: {
45-
objects: () => {
46-
return [
47-
{ id: '1', propertyId: '1' },
48-
{ id: '2', propertyId: '1' },
49-
];
50-
},
51-
propertyById: (_, args) => getProperty(args.id),
52-
propertiesByIds: (_, args) => args.ids.map(getProperty),
53-
},
43+
resolvers: {
44+
Query: {
45+
objects: () => {
46+
return [
47+
{ id: '1', propertyId: '1' },
48+
{ id: '2', propertyId: '1' },
49+
];
5450
},
55-
});
56-
57-
const subschemas = [subschema];
58-
const typeDefs = /* GraphQL */ `
51+
propertyById: (_, args) => getProperty(args.id),
52+
propertiesByIds: (_, args) => args.ids.map(getProperty),
53+
},
54+
},
55+
});
56+
57+
const subschemas = [subschema];
58+
const typeDefs = /* GraphQL */ `
5959
extend type Object {
6060
property: Property
6161
}
6262
`;
6363

64-
const query = /* GraphQL */ `
64+
const query = /* GraphQL */ `
6565
query {
6666
objects {
6767
id
@@ -72,91 +72,91 @@ describe('preserves error path indices', () => {
7272
}
7373
`;
7474

75-
const expected = {
76-
errors: [
77-
{
78-
message: 'Not Found',
79-
extensions: { id: '1' },
80-
path: ['objects', 0, 'property'],
81-
},
82-
{
83-
message: 'Not Found',
84-
extensions: { id: '1' },
85-
path: ['objects', 1, 'property'],
86-
},
87-
],
88-
data: {
89-
objects: [
90-
{
91-
id: '1',
92-
property: null,
93-
},
94-
{
95-
id: '2',
96-
property: null,
97-
},
98-
],
75+
const expected = {
76+
errors: [
77+
{
78+
message: 'Not Found',
79+
extensions: { id: '1' },
80+
path: ['objects', 0, 'property'],
81+
},
82+
{
83+
message: 'Not Found',
84+
extensions: { id: '1' },
85+
path: ['objects', 1, 'property'],
86+
},
87+
],
88+
data: {
89+
objects: [
90+
{
91+
id: '1',
92+
property: null as null,
9993
},
100-
};
101-
102-
test('using delegateToSchema', async () => {
103-
const schema = stitchSchemas({
104-
subschemas,
105-
typeDefs,
106-
resolvers: {
107-
Object: {
108-
property: {
109-
selectionSet: '{ propertyId }',
110-
resolve: (source, _, context, info) => {
111-
return delegateToSchema({
112-
schema: subschema,
113-
fieldName: 'propertyById',
114-
args: { id: source.propertyId },
115-
context,
116-
info,
117-
});
118-
},
119-
},
120-
},
94+
{
95+
id: '2',
96+
property: null as null,
97+
},
98+
],
99+
},
100+
};
101+
102+
test('using delegateToSchema', async () => {
103+
const schema = stitchSchemas({
104+
subschemas,
105+
typeDefs,
106+
resolvers: {
107+
Object: {
108+
property: {
109+
selectionSet: '{ propertyId }',
110+
resolve: (source, _, context, info) => {
111+
return delegateToSchema({
112+
schema: subschema,
113+
fieldName: 'propertyById',
114+
args: { id: source.propertyId },
115+
context,
116+
info,
117+
});
121118
},
122-
});
123-
124-
125-
const result = await normalizedExecutor({
126-
schema,
127-
document: parse(query),
128-
})
129-
130-
expect(getProperty).toBeCalledTimes(2);
131-
expect(result).toMatchObject(expected);
119+
},
120+
},
121+
},
132122
});
133123

134-
test('using batchDelegateToSchema', async () => {
135-
const schema = stitchSchemas({
136-
subschemas,
137-
typeDefs,
138-
resolvers: {
139-
Object: {
140-
property: {
141-
selectionSet: '{ propertyId }',
142-
resolve: (source, _, context, info) => batchDelegateToSchema({
143-
schema: subschema,
144-
fieldName: 'propertiesByIds',
145-
key: source.propertyId,
146-
context,
147-
info,
148-
}),
149-
},
150-
},
151-
},
152-
});
124+
const result = await normalizedExecutor({
125+
schema,
126+
document: parse(query),
127+
});
153128

154-
const result = await normalizedExecutor({
155-
schema,
156-
document: parse(query),
157-
})
129+
expect(getProperty).toBeCalledTimes(2);
130+
expect(result).toMatchObject(expected);
131+
});
132+
133+
test('using batchDelegateToSchema', async () => {
134+
const schema = stitchSchemas({
135+
subschemas,
136+
typeDefs,
137+
resolvers: {
138+
Object: {
139+
property: {
140+
selectionSet: '{ propertyId }',
141+
resolve: (source, _, context, info) =>
142+
batchDelegateToSchema({
143+
schema: subschema,
144+
fieldName: 'propertiesByIds',
145+
key: source.propertyId,
146+
context,
147+
info,
148+
}),
149+
},
150+
},
151+
},
152+
});
158153

159-
expect(getProperty).toBeCalledTimes(1);
160-
expect(result).toMatchObject(expected);
154+
const result = await normalizedExecutor({
155+
schema,
156+
document: parse(query),
161157
});
162-
});
158+
159+
expect(getProperty).toBeCalledTimes(1);
160+
expect(result).toMatchObject(expected);
161+
});
162+
});

0 commit comments

Comments
 (0)