Skip to content

Commit 90215c2

Browse files
authored
fix: Updated index.mjs file to be modified for Apollo subgraph Federation 2 features (aws#126)
There was an issue with the Apollo index.mjs file when generated with --create-update-apollo-server-subgraph as it did not include support for the Apollo Subgraph Federation 2 features. Updated so that when user runs --create-update-apollo-server-subgraph the index.mjs file includes the support for the subgraph federation 2 features and if run with just --create-update-apollo-server, the index.mjs file is not modified and same as the original template. Also added an index.mjs file check to the apollo subgraph integration test (Case09) to ensure the index.mjs file is always modified correctly to add support for the subgraph federation 2 features.
1 parent 8ecba76 commit 90215c2

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,6 @@ permissions and limitations under the License.
118118
an input
119119
schema ([#118](https://github.com/aws/amazon-neptune-for-graphql/pull/118))
120120
* Fixed duplicated nodes and edges from nodes with
121-
multi-labels ([#125](https://github.com/aws/amazon-neptune-for-graphql/pull/125))
121+
multi-labels ([#125](https://github.com/aws/amazon-neptune-for-graphql/pull/125))
122+
* Updated Apollo subgraph to allow use of Federation 2 features.
123+
([#126](https://github.com/aws/amazon-neptune-for-graphql/pull/126))

src/zipPackage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function createZip({targetZipFilePath, includePaths = [], includeContent =
4949
output.on('close', () => resolve());
5050
archive.on('error', err => reject(err));
5151
});
52-
52+
5353
archive.pipe(output);
5454

5555
includePaths.forEach(includePath => {

templates/ApolloServer/index.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import dotenv from 'dotenv';
88

99
dotenv.config();
1010

11-
const typeDefs = parse(readFileSync('./output.schema.graphql', 'utf-8'));
11+
const fileContent = readFileSync('./output.schema.graphql', 'utf-8');
12+
let schema = fileContent;
13+
if (process.env.SUBGRAPH === 'true') {
14+
schema = `extend schema @link(
15+
url: "https://specs.apollo.dev/federation/v2.0"
16+
import: ["@key", "@shareable"]
17+
)${fileContent}`;
18+
}
19+
const typeDefs = parse(schema);
1220
const queryDefinition = typeDefs.definitions.find(
1321
definition => definition.kind === 'ObjectTypeDefinition' && definition.name.value === 'Query'
1422
);

test/testLib.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ async function testApolloArtifacts(outputFolderPath, testDbInfo, subgraph = fals
226226
];
227227
const actualEnvContent = fs.readFileSync(path.join(outputFolderPath, 'unzipped', '.env'), 'utf8');
228228
expect(actualEnvContent).toEqual(expectedEnvContent.join('\n'));
229+
230+
const actualIndexContent = fs.readFileSync(path.join(outputFolderPath, 'unzipped', 'index.mjs'), 'utf8');
231+
expect(actualIndexContent).toContain('https://specs.apollo.dev/federation/v2.0');
229232
});
230233
}
231234

0 commit comments

Comments
 (0)