@@ -7,13 +7,10 @@ const Sentry = require('@sentry/node');
77const compression = require ( 'compression' ) ;
88const morgan = require ( 'morgan' ) ;
99const { ApolloServer } = require ( 'apollo-server-express' ) ;
10- const { ApolloGateway, RemoteGraphQLDataSource } = require ( "@apollo/gateway" ) ;
10+ const { ApolloGateway, IntrospectAndCompose, RemoteGraphQLDataSource } = require ( "@apollo/gateway" ) ;
11+ const { ApolloServerPluginLandingPageGraphQLPlayground } = require ( 'apollo-server-core' ) ;
1112
1213const CLIENT_API_URL = process . env . CLIENT_API_URL || 'https://api.stage.datacite.org/client-api/graphql' ;
13- // const PROFILES_URL = process.env.PROFILES_URL || 'https://api.stage.datacite.org/profiles/graphql';
14- // const API_URL = process.env.API_URL || 'https://api.stage.datacite.org/api/graphql';
15- // const RE3DATA_URL = process.env.RE3DATA_URL || 'https://api.stage.datacite.org/re3data/graphql';
16- // const STRAPI_URL = process.env.STRAPI_URL || 'https://strapi.stage.datacite.org/graphql';
1714
1815class AuthenticationHeader extends RemoteGraphQLDataSource {
1916 willSendRequest ( { request, context } ) {
@@ -24,19 +21,17 @@ class AuthenticationHeader extends RemoteGraphQLDataSource {
2421}
2522
2623const gateway = new ApolloGateway ( {
27- serviceList : [
28- { name : 'client-api' , url : CLIENT_API_URL } ,
29- // { name: 'profiles', url: PROFILES_URL },
30- // { name: 'strapi', url: STRAPI_URL }
31- // { name: 'api', url: API_URL },
32- // { name: 're3data', url: RE3DATA_URL }
33- // more services
34- ] ,
24+ supergraphSdl : new IntrospectAndCompose ( {
25+ subgraphs : [
26+ { name : 'client-api' , url : CLIENT_API_URL } ,
27+ ] ,
28+ } ) ,
3529 buildService ( { name, url } ) {
3630 return new AuthenticationHeader ( { url } ) ;
3731 } ,
3832} ) ;
3933
34+ ( async ( ) => {
4035const server = new ApolloServer ( {
4136 gateway,
4237 cors : false ,
@@ -47,11 +42,13 @@ const server = new ApolloServer({
4742 apiKey : process . env . APOLLO_API_KEY ,
4843 graphVariant : process . env . NODE_ENV
4944 } ,
50- playground : {
51- settings : {
52- 'editor.theme' : 'light' ,
53- }
54- } ,
45+ plugins : [
46+ ApolloServerPluginLandingPageGraphQLPlayground ( {
47+ settings : {
48+ 'editor.theme' : 'light' ,
49+ }
50+ } ) ,
51+ ] ,
5552 context : ( { req } ) => {
5653 // Get the user token from the headers
5754 const token = req . headers . authorization || '' ;
@@ -76,6 +73,7 @@ app.use(compression());
7673// logging
7774app . use ( morgan ( 'combined' ) ) ;
7875
76+ await server . start ( ) ;
7977server . applyMiddleware ( { app, cors : false } ) ;
8078
8179// disable headers
@@ -86,4 +84,5 @@ if (typeof(PhusionPassenger) !== 'undefined') {
8684} else {
8785 app . listen ( 4000 ) ;
8886}
89-
87+ } ) ( ) ;
88+
0 commit comments