Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/__tests__/schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'path';
import { Api } from '../resources/Api';
import { Schema } from '../resources/Schema';
import * as given from './given';
Expand Down Expand Up @@ -229,6 +230,29 @@ describe('schema', () => {
expect(output).toContain('AWSJSON');
});

it('should support absolute schema paths regardless of servicePath', () => {
const plugin = given.plugin();
// servicePath deliberately points somewhere the schema is NOT;
// an absolute schema path must still be read correctly.
plugin.serverless.config.servicePath = path.resolve('does', 'not', 'exist');
const api = new Api(given.appSyncConfig(), plugin);
const absolutePath = path.resolve(
'src/__tests__/fixtures/schemas/single/schema.graphql',
);
const schema = new Schema(api, [absolutePath]);
expect(schema.generateSchema()).toContain('type Query');
});

it('should resolve relative schema paths against servicePath', () => {
const plugin = given.plugin();
plugin.serverless.config.servicePath = process.cwd();
const api = new Api(given.appSyncConfig(), plugin);
const schema = new Schema(api, [
'src/__tests__/fixtures/schemas/single/schema.graphql',
]);
expect(schema.generateSchema()).toContain('type Query');
});

it('should return single files schemas as-is', () => {
const api = new Api(given.appSyncConfig(), plugin);
const schema = new Schema(api, [
Expand Down
5 changes: 4 additions & 1 deletion src/resources/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export class Schema {
globby.sync(
this.schemas.map((schema) =>
path
.join(this.api.plugin.serverless.config.servicePath, schema)
// `path.resolve` keeps relative paths resolved against the
// service directory while leaving absolute paths untouched
// (`path.join` would incorrectly prefix them with servicePath).
.resolve(this.api.plugin.serverless.config.servicePath, schema)
.replace(/\\/g, '/'),
),
),
Expand Down
Loading