@things-factory/shell 10.1.146 → 10.1.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/introspection-for-signed-in.d.ts +14 -0
- package/dist-server/introspection-for-signed-in.js +43 -0
- package/dist-server/introspection-for-signed-in.js.map +1 -0
- package/dist-server/server-dev.js +3 -1
- package/dist-server/server-dev.js.map +1 -1
- package/dist-server/server.js +4 -7
- package/dist-server/server.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/tests/introspection-for-signed-in.test.ts +48 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/shell",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.147",
|
|
4
4
|
"description": "Core module for framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"things-factory": "bin/things-factory",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"pg": "^8.7.3",
|
|
127
127
|
"sqlite3": "^5.0.8"
|
|
128
128
|
},
|
|
129
|
-
"gitHead": "
|
|
129
|
+
"gitHead": "df93dddb6ac19a27c32fad21e29ca0ce02d08eb6"
|
|
130
130
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ApolloServer } from '@apollo/server'
|
|
2
|
+
import { buildSchema } from 'graphql'
|
|
3
|
+
|
|
4
|
+
import { introspectionForSignedIn } from '../server/introspection-for-signed-in'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Schema reading is open to a signed-in user and refused to anyone else; `__typename` is always open
|
|
8
|
+
* (ADR-0126). The server keeps Apollo's introspection on, as shell's servers do.
|
|
9
|
+
*/
|
|
10
|
+
const schema = buildSchema(`type Query { hello: String }`)
|
|
11
|
+
|
|
12
|
+
const server = new ApolloServer({ schema, introspection: true, plugins: [introspectionForSignedIn()] })
|
|
13
|
+
|
|
14
|
+
beforeAll(() => server.start())
|
|
15
|
+
afterAll(() => server.stop())
|
|
16
|
+
|
|
17
|
+
const ask = async (query: string, user?: object) => {
|
|
18
|
+
const response = await server.executeOperation({ query }, { contextValue: { state: { user } } })
|
|
19
|
+
return response.body.kind === 'single' ? response.body.singleResult : undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('reading the schema', () => {
|
|
23
|
+
it('is refused without a signed-in user', async () => {
|
|
24
|
+
const result = await ask('{ __schema { queryType { name } } }')
|
|
25
|
+
expect(result?.errors?.[0]?.extensions?.code).toBe('UNAUTHENTICATED')
|
|
26
|
+
expect(result?.data).toBeUndefined()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('is refused for __type and inside a fragment too', async () => {
|
|
30
|
+
expect((await ask('{ __type(name: "Query") { name } }'))?.errors?.[0]?.extensions?.code).toBe('UNAUTHENTICATED')
|
|
31
|
+
expect(
|
|
32
|
+
(await ask('query { ...schema } fragment schema on Query { __schema { queryType { name } } }'))?.errors?.[0]
|
|
33
|
+
?.extensions?.code
|
|
34
|
+
).toBe('UNAUTHENTICATED')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('answers a signed-in user', async () => {
|
|
38
|
+
const result = await ask('{ __schema { queryType { name } } }', { id: 'u-1' })
|
|
39
|
+
expect(result?.errors).toBeUndefined()
|
|
40
|
+
expect((result?.data as any).__schema.queryType.name).toBe('Query')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('leaves __typename open to everyone', async () => {
|
|
44
|
+
const result = await ask('{ __typename }')
|
|
45
|
+
expect(result?.errors).toBeUndefined()
|
|
46
|
+
expect((result?.data as any).__typename).toBe('Query')
|
|
47
|
+
})
|
|
48
|
+
})
|