Skip to content

Commit

Permalink
chore: fix failing existing e2e due to render issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phani-srikar committed Apr 25, 2023
1 parent f5a3729 commit 025fa2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/amplify-codegen/src/commands/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ async function writeGeneratedStatements(language, generatedStatements, outputPat
if (separateFiles) {
['queries', 'mutations', 'subscriptions', 'fragments'].forEach(op => {
const ops = generatedStatements[op];
if (ops.length) {
fs.writeFileSync(path.resolve(path.join(outputPath, `${op}.${fileExtension}`)), ops);
if (ops.size) {
// This will change post top level codegen changes
fs.writeFileSync(path.resolve(path.join(outputPath, `${op}.${fileExtension}`)), JSON.stringify(Object.fromEntries(ops)));
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getSchemaType } from '../../../src/generator/utils/getSchemaType';
import { SchemaType } from '../../../src/generator/types';
import { resolve, join } from 'path';
import * as fs from 'fs';

describe('Get Appropriate GraphQL Schema Type', () => {
it('detects the GraphQL introspection schema type', () => {
const schemaPath = resolve(__dirname, join('..', '..', '..', 'fixtures', 'schema.json'));
const schema = fs.readFileSync(schemaPath, 'utf8');

expect(getSchemaType(schema)).toEqual(SchemaType.INTROSPECTION);
});

it('detects the GraphQL SDL schema type', () => {
const schemaPath = resolve(__dirname, join('..', '..', '..', 'fixtures', 'schema.graphql'));
const schema = fs.readFileSync(schemaPath, 'utf8');

expect(getSchemaType(schema)).toEqual(SchemaType.SDL);
});

it('defaults to return the GraphQL SDL schema type', () => {
const schema = `{"data": {"invalid_key": "invalid_value"}`;

expect(getSchemaType(schema)).toEqual(SchemaType.SDL);
});
});

0 comments on commit 025fa2f

Please sign in to comment.