graphql-engine/server/tests-py/remote_schemas/nodejs/apollo_server_1.js
paritosh-08 95adde4ce2 server: support for Apollo federation
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4584
Co-authored-by: Auke Booij <164426+abooij@users.noreply.github.com>
GitOrigin-RevId: 0f60c263efb5fbaa25620dd8159e8cfda25a61b2
2022-07-25 15:54:41 +00:00

54 lines
941 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(4003).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});