graphql-engine/server/tests-py/remote_schemas/nodejs/apollo_server_1.js
Samir Talwar 8d7c089273 server/tests-py: Start some node.js test services on random ports.
Where possible, we start the services on random ports, to avoid
port conflicts when parallelizing tests in the future.

When this isn't possible, we explicitly state the port, and wait for the
service to start. This is typically because the GraphQL Engine has already
started with knowledge of the relevant service passed in through an
environment variable.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5542
GitOrigin-RevId: b51a095b8710e3ff20d1edb13aa576c5272a5565
2022-09-07 16:26:10 +00:00

55 lines
964 B
JavaScript

const { ApolloServer, gql } = require('apollo-server');
const { buildSubgraphSchema } = require('@apollo/subgraph');
const user = [
{
id: 1,
city: 'New York'
},
{
id: 2,
city: 'Bangalore'
},
{
id: 3,
city: 'Melbourne'
},
{
id: 4,
city: 'New Delhi'
}
];
const typeDefs = gql`
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@extends", "@external", "@shareable"])
type Query {
getUserData(id: Int!): user
}
type user @key(fields: "id") @extends {
id: Int! @external
city: String
}
`;
const resolvers = {
Query: {
getUserData(parent, args, context, info) {
return user.find(user => user.id === args.id);
}
}
}
const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers })
});
server.listen({ port: process.env.PORT }).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});