-
Notifications
You must be signed in to change notification settings - Fork 153
/
wundergraph.config.ts
executable file
·115 lines (106 loc) · 3.16 KB
/
wundergraph.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
Application,
configurePublishWunderGraphAPI,
configureWunderGraphApplication,
cors,
introspect,
templates,
} from '@wundergraph/sdk';
import server from './wundergraph.server';
import operations from './wundergraph.operations';
/*
uncomment this section to create an API from multiple federated GraphQL upstreams
const federatedApi = introspect.federation({
upstreams: [
{
url: "http://localhost:4001/graphql"
},
{
url: "http://localhost:4002/graphql"
},
{
url: "http://localhost:4003/graphql"
},
{
url: "http://localhost:4004/graphql",
// You can use headers to securely communicate with GraphQL upstreams
headers: builder => builder
// add a static Header to all upstream Requests
.addStaticHeader("AuthToken","staticToken")
// forward the client Request header Authorization to the upstream request using the same Header name
.addClientRequestHeader("Authorization","Authorization")
},
]
});
*/
/*
uncomment this section to create an API from an OpenAPI Specification
const openAPI = introspect.openApi({
source: {
kind: "file",
filePath: "my_api_oas.json"
},
headers: builder => builder
// add a static Header to all upstream Requests
.addStaticHeader("AuthToken","staticToken")
// forward the client Request header Authorization to the upstream request using the same Header name
.addClientRequestHeader("Authorization","Authorization")
});
*/
/*
uncomment this section to create an API from a GraphQL upstream
const graphQLAPI = introspect.graphql({
url: "http://localhost:4000",
headers: builder => builder
// add a static Header to all upstream Requests
.addStaticHeader("AuthToken","staticToken")
// forward the client Request header Authorization to the upstream request using the same Header name
.addClientRequestHeader("Authorization","Authorization")
});*/
const spaceX = introspect.graphql({
apiNamespace: 'spacex',
url: 'https://api.spacex.land/graphql/',
});
const myApplication = new Application({
name: 'app',
apis: [
spaceX,
/*federatedApi,
openAPI,
graphQLAPI*/
],
});
// configureWunderGraph emits the configuration
configureWunderGraphApplication({
application: myApplication,
server,
operations,
codeGenerators: [
{
templates: [
// use all the typescript react templates to generate a client
...templates.typescript.all,
templates.typescript.operations,
templates.typescript.linkBuilder,
],
// create-react-app expects all code to be inside /src
// path: "../frontend/src/generated",
},
],
cors: {
...cors.allowAll,
allowedOrigins:
process.env.NODE_ENV === 'production'
? [
// change this before deploying to production to the actual domain where you're deploying your app
'http://localhost:3000',
]
: ['http://localhost:3000'],
},
dotGraphQLConfig: {
hasDotWunderGraphDirectory: false,
},
security: {
enableGraphQLEndpoint: process.env.NODE_ENV !== 'production'
},
});