mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
8d7c089273
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
55 lines
964 B
JavaScript
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}`);
|
|
});
|