graphql-hive / graphql-hive/SOFA

Integrating SOFA with Apollo Federation

Open
#214 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.1k
Forks
91
Avg merge
5h 10m
Merged PRs (30d)
1

Description

I have a microservice API that is using SOFA and seems to be serving up data via REST just fine:

```
const { ApolloServer } = require('apollo-server-express');
const { buildFederatedSchema } = require('@apollo/federation');
const express = require('express');
const { useSofa } = require('sofa-api');

const { resolvers } = require('./schema/resolvers');
const { typeDefs } = require('./schema/typeDefs');

const graphQL = new ApolloServer({
schema: buildFederatedSchema(
{
typeDefs,
resolvers
}
)
});

const app = express();

app.use('/api', useSofa({
schema: buildFederatedSchema({
typeDefs,
resolvers
})
}));

graphQL.applyMiddleware({ app });

const port = process.env.PORT || 4001;

app.listen({ port }, () => {
console.log('Server ready http://localhost: ' + port);
});
```

But then, when I try to federate that microservice, and any number of microservices, into a gateway API as instantiated below, I recieve a `null` value whenever I make a REST query.
```const express = require('express');
const { useSofa, OpenAPI } = require('sofa-api');
const { ApolloServer } = require('apollo-server-express');
const { ApolloGateway } = require("@apollo/gateway");

const gateway = new ApolloGateway({
serviceList: [
{ name: "salesLineItem", url: '${process.env.NUTRIEN_SALES_DOCUMENT_SERVICE_URL}/graphql' },
{ name: "salesDocument", url: '${process.env.NUTRIEN_SALES_LINE_ITEM_SERVICE_URL}/graphql' },
{ name: "productPrice", url: '${process.env.NUTRIEN_PRODUCT_PRICE_SERVICE_URL}/graphql' },
]
});

(async () => {
const { schema, executor } = await gateway.load();
console.log('Gateway schema', JSON.stringify(schema));
const graphql = new ApolloServer({ schema, executor });

const app = express();

app.use(
'/api',
useSofa({
schema
}),
);

graphql.applyMiddleware({ app });

app.listen({ port: process.env.PORT }, () => {
console.log('Server ready http://localhost:' + ${process.env.PORT});
});
})();
```

So, the same query succeeds when made against the microservice, but returns `null` when made against the federated gateway service. Is it not possible to use SOFA with a federated Apollo server?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the REST query through the gateway entry point, focusing on ApolloGateway's serviceList and app.use('/api', useSofa({ schema })). Compare that result with the same query against the microservice setup. Done means determining whether federated Apollo schemas can return the expected REST data through SOFA, with a fix or a documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, graphql, javascript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.