11import { readFileSync } from 'fs' ;
2- import { ApolloServer , ApolloError , gql } from 'apollo-server' ;
2+ import { gql } from 'graphql-tag' ;
3+ import { GraphQLError } from 'graphql' ;
4+ import { ApolloServer } from '@apollo/server' ;
5+ import { startStandaloneServer } from '@apollo/server/standalone' ;
36import { buildSubgraphSchema } from '@apollo/subgraph' ;
47
5- const port = process . env . PRODUCTS_PORT || 4001 ;
8+ const serverPort = parseInt ( process . env . PRODUCTS_PORT || "" ) || 4001 ;
69
710const deprecatedProduct = {
811 sku : "apollo-federation-v1" ,
@@ -125,7 +128,7 @@ const resolvers = {
125128 /** @type {(user: { email: String, totalProductsCreated: Number, yearsOfEmployment: Number }, args: any, context: any) => any } */
126129 averageProductsCreatedPerYear : ( user , args , context ) => {
127130 if ( user . email != "support@apollographql.com" ) {
128- throw new ApolloError ( "user.email was not 'support@apollographql.com'" )
131+ throw new GraphQLError ( "user.email was not 'support@apollographql.com'" )
129132 }
130133 return Math . round ( user . totalProductsCreated / user . yearsOfEmployment ) ;
131134 } ,
@@ -152,6 +155,6 @@ const server = new ApolloServer({
152155 schema : buildSubgraphSchema ( { typeDefs, resolvers } ) ,
153156} ) ;
154157
155- server
156- . listen ( { port } )
157- . then ( ( { url } ) => console . log ( `Products subgraph ready at ${ url } ` ) ) ;
158+ startStandaloneServer ( server , {
159+ listen : { port : serverPort } ,
160+ } ) . then ( ( { url } ) => console . log ( `🚀 Products subgraph ready at ${ url } ` ) ) ;
0 commit comments