Skip to content

Commit

Permalink
fix: allow integer to Float input coercion (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenimus authored Feb 6, 2025
1 parent 3950797 commit 51c3d8e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions composition-go/index.global.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composition/src/normalization/normalization-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class NormalizationFactory {
return argumentValue.kind === Kind.BOOLEAN;
}
case FLOAT_SCALAR: {
return argumentValue.kind === Kind.FLOAT;
return argumentValue.kind === Kind.FLOAT || argumentValue.kind === Kind.INT;
}
case ID_SCALAR: {
return argumentValue.kind === Kind.STRING || argumentValue.kind === Kind.INT;
Expand Down
34 changes: 34 additions & 0 deletions composition/tests/directives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ describe('Directive tests', () => {
expect(warnings).toHaveLength(0);
});

test('that a integer can be coerced into a Float', () => {
const { errors, normalizationResult, warnings } = normalizeSubgraph(nk.definitions, nk.name);
expect(errors).toBeUndefined();
expect(schemaToSortedNormalizedString(normalizationResult!.schema)).toBe(
normalizeString(
schemaQueryDefinition +
baseDirectiveDefinitions +
`
directive @z(float: Float!) on FIELD_DEFINITION
type Query {
dummy: String! @z(float: 1)
}
scalar openfed__FieldSet
`,
),
);
expect(warnings).toHaveLength(0);
});

test('that @specifiedBy is supported', () => {
const { errors } = normalizeSubgraph(subgraphA.definitions, subgraphA.name);
expect(errors).toBeUndefined();
Expand Down Expand Up @@ -479,6 +501,18 @@ const nj: Subgraph = {
`),
};

const nk: Subgraph = {
name: 'nk',
url: '',
definitions: parse(`
directive @z(float: Float!) on FIELD_DEFINITION
type Query {
dummy: String! @z(float: 1)
}
`),
};

const subgraphA: Subgraph = {
name: 'subgraph-a',
url: '',
Expand Down

0 comments on commit 51c3d8e

Please sign in to comment.