mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
95adde4ce2
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
54 lines
941 B
JavaScript
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}`);
|
|
}); |