Skip to content

Commit c30effa

Browse files
Merge pull request #441 from Workgrid/support-graphql
ETSWORK-17208 Support new GraphQL integration
2 parents 5810137 + da522d8 commit c30effa

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

packages/workgrid-client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@workgrid/client",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"main": "dist/client.js",
55
"types": "dist/client.d.ts",
66
"files": [
@@ -33,4 +33,4 @@
3333
]
3434
},
3535
"license": "ISC"
36-
}
36+
}

packages/workgrid-client/src/client.test.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,39 @@ const server = setupServer(
131131
suggestions: ['ask another'],
132132
})
133133
)
134+
}),
135+
rest.post(`https://company-code.workgrid.com/graphql`, (req, res, ctx) => {
136+
return res(
137+
ctx.json({
138+
data: {
139+
me: {
140+
id: '12345',
141+
space: {
142+
id: '17dacf8d-ee8d-45ff-9d6b-f984e789c4e3',
143+
apps: {
144+
edges: [
145+
{
146+
node: {
147+
entrypoint: 'f19b6a81-7648-4c72-97df-87f45e24191f',
148+
title: 'Intranet Admin Tools',
149+
},
150+
},
151+
{
152+
node: {
153+
entrypoint: '2b4d2ae8-fde4-4c8a-b4f1-8e349c3fcf68',
154+
title: 'Quick Links',
155+
},
156+
},
157+
],
158+
pageInfo: {
159+
hasNextPage: false,
160+
},
161+
},
162+
},
163+
},
164+
},
165+
})
166+
)
134167
})
135168
)
136169

@@ -204,6 +237,65 @@ describe('@workgrid/client', () => {
204237
`)
205238
})
206239

240+
test('graphql', async () => {
241+
const gql = String.raw
242+
const query = gql`
243+
query appsQuery($spaceId: ID!) {
244+
me {
245+
space(spaceId: $spaceId) {
246+
id
247+
apps {
248+
edges {
249+
node {
250+
entrypoint
251+
title
252+
}
253+
}
254+
pageInfo {
255+
hasNextPage
256+
}
257+
}
258+
}
259+
}
260+
}
261+
`
262+
263+
const variables = {
264+
spaceId: '17dacf8d-ee8d-45ff-9d6b-f984e789c4e3',
265+
}
266+
const result = await client.mutate('graphql', { query, variables })
267+
268+
expect(result).toMatchInlineSnapshot(`
269+
Object {
270+
"me": Object {
271+
"id": "12345",
272+
"space": Object {
273+
"apps": Object {
274+
"edges": Array [
275+
Object {
276+
"node": Object {
277+
"entrypoint": "f19b6a81-7648-4c72-97df-87f45e24191f",
278+
"title": "Intranet Admin Tools",
279+
},
280+
},
281+
Object {
282+
"node": Object {
283+
"entrypoint": "2b4d2ae8-fde4-4c8a-b4f1-8e349c3fcf68",
284+
"title": "Quick Links",
285+
},
286+
},
287+
],
288+
"pageInfo": Object {
289+
"hasNextPage": false,
290+
},
291+
},
292+
"id": "17dacf8d-ee8d-45ff-9d6b-f984e789c4e3",
293+
},
294+
},
295+
}
296+
`)
297+
})
298+
207299
test('customMutate', async () => {
208300
const options = { mutationFn: async () => ({ message: 'Hello, world!' }) }
209301
const result = client.customMutate('mutation-key', undefined, options)

packages/workgrid-client/src/client.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,29 @@ setTypedMutationDefaults('deleteNotification', (client) => ({
528528
},
529529
}))
530530

531+
// graphql
532+
533+
// ================================================================================================================================
534+
535+
/** @beta */
536+
export interface Mutations {
537+
graphql: Mutation<['graphql'], { query: string; variables: unknown }, unknown>
538+
}
539+
540+
setTypedMutationDefaults('graphql', (client) => ({
541+
mutationFn: async (params) => {
542+
const { query, variables } = params
543+
544+
const data = {
545+
query,
546+
variables,
547+
}
548+
549+
const response = await client.httpClient.post('graphql', data)
550+
return response.data.data /* unwrap graphql */
551+
},
552+
}))
553+
531554
// getActivity
532555
// ================================================================================================================================
533556

0 commit comments

Comments
 (0)