Skip to content

Commit 88626d3

Browse files
committedMay 14, 2020
fix: CLI graphql typeDefs and resolvers
1 parent 724fc66 commit 88626d3

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed
 

‎packages/daf-cli/src/graphql.ts

+16-41
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { SdrGql } from 'daf-selective-disclosure'
88
import merge from 'lodash.merge'
99
import { agent } from './setup'
1010
import { listen } from './services'
11-
import { makeExecutableSchema, mergeSchemas } from 'graphql-tools'
1211
import { getConfiguration } from './config'
1312

1413
program
@@ -20,66 +19,42 @@ program
2019
.action(async cmd => {
2120
await agent
2221
const { graphql } = getConfiguration()
23-
const schemas = [
24-
makeExecutableSchema({
25-
typeDefs: Gql.baseTypeDefs + Gql.Core.typeDefs,
26-
resolvers: Gql.Core.resolvers
27-
})
28-
]
22+
const typeDefs = [Gql.baseTypeDefs, Gql.Core.typeDefs]
23+
let resolvers = Gql.Core.resolvers
2924

3025
if (graphql.resolvers.IdentityManager) {
31-
schemas.push(
32-
makeExecutableSchema({
33-
typeDefs: Gql.baseTypeDefs + Gql.IdentityManager.typeDefs,
34-
resolvers: Gql.IdentityManager.resolvers
35-
})
36-
)
26+
typeDefs.push(Gql.IdentityManager.typeDefs)
27+
resolvers = merge(resolvers, Gql.IdentityManager.resolvers)
3728
}
3829

3930
if (graphql.resolvers.TrustGraph) {
40-
schemas.push(
41-
makeExecutableSchema({
42-
typeDefs: Gql.baseTypeDefs + TrustGraphGql.typeDefs,
43-
resolvers: TrustGraphGql.resolvers
44-
})
45-
)
31+
typeDefs.push(TrustGraphGql.typeDefs)
32+
resolvers = merge(resolvers, TrustGraphGql.resolvers)
4633
}
4734

4835
if (graphql.resolvers.DIDComm) {
49-
schemas.push(
50-
makeExecutableSchema({
51-
typeDefs: Gql.baseTypeDefs + DIDCommGql.typeDefs,
52-
resolvers: DIDCommGql.resolvers
53-
})
54-
)
36+
typeDefs.push(DIDCommGql.typeDefs)
37+
resolvers = merge(resolvers, DIDCommGql.resolvers)
5538
}
5639

5740
if (graphql.resolvers.W3c) {
58-
schemas.push(
59-
makeExecutableSchema({
60-
typeDefs: Gql.baseTypeDefs + W3cGql.typeDefs,
61-
resolvers: W3cGql.resolvers
62-
})
63-
)
41+
typeDefs.push(W3cGql.typeDefs)
42+
resolvers = merge(resolvers, W3cGql.resolvers)
6443
}
6544

6645
if (graphql.resolvers.Sdr) {
67-
schemas.push(
68-
makeExecutableSchema({
69-
typeDefs: Gql.baseTypeDefs + SdrGql.typeDefs,
70-
resolvers: SdrGql.resolvers
71-
})
72-
)
46+
typeDefs.push(SdrGql.typeDefs)
47+
resolvers = merge(resolvers, SdrGql.resolvers)
7348
}
7449

75-
const schema = mergeSchemas({ schemas })
76-
7750
const server = new ApolloServer({
78-
schema,
51+
typeDefs,
52+
resolvers,
7953
context: async ({ req }) => {
8054
if (graphql.apiKey) {
81-
const token = req.headers.authorization || ''
55+
const token = req.headers.authorization || ''
8256
if (token !== 'Bearer ' + graphql.apiKey) {
57+
console.log({token})
8358
throw Error('Auth error')
8459
}
8560
}

0 commit comments

Comments
 (0)
Please sign in to comment.