Reputation: 187
We can configure apollo-server-express
like this:
const server = new ApolloServer({
typeDefs: schema,
resolvers: resolvers,
introspection: true,
playground: true,
});
server.applyMiddleware({
app,
path: "/graphql"
});
Here the path
is specific to only one endpoint. So, is it possible to make separate API routes in GraphQL (like REST) using Node.js and Express framework?
Upvotes: 1
Views: 950
Reputation: 84687
You can create separate separate endpoints for different GraphQL services that use different schemas. This is most commonly done when you're providing services that are consumed by different types of clients. For example, you might have some public app and a separate private app for managing the public one -- rather than having the apps share a single schema, you can use two separate services and have each app connect to their own. Likewise, you might have a service that's used just by your app(s) and then a separate public API you make available for developer integration.
However, you should not utilize separate endpoints to arbitrarily break up a schema. You will not gain anything by doing that and will instead end up with unnecessary duplication and complicate things for any clients consuming your API, since most GraphQL client libraries expect a single URL.
Upvotes: 1