Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(transforms): support custom scalar input variables on root fields…
Browse files Browse the repository at this point in the history
… when transforming.

Fixes #18.
  • Loading branch information
yaacovCR committed Mar 26, 2020
1 parent a9b1754 commit a666aed
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stitching/resolvers.ts
Expand Up @@ -111,7 +111,7 @@ function createProxyingResolver(
schema: schema as GraphQLSchema,
operation,
fieldName,
args: {},
args,
context,
info,
transforms,
Expand Down
66 changes: 66 additions & 0 deletions src/test/testTransforms.ts
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai';
import {
GraphQLSchema,
GraphQLNamedType,
GraphQLScalarType,
graphql,
Kind,
SelectionSetNode,
Expand All @@ -28,6 +29,71 @@ import {
} from '../transforms';

describe('transforms', () => {
describe('base transform function', () => {
let schema: GraphQLSchema;
let scalarTest = `
scalar TestScalar
type TestingScalar {
value: TestScalar
}
type Query {
testingScalar(input: TestScalar): TestingScalar
}
`;

let scalarSchema: GraphQLSchema;

scalarSchema = makeExecutableSchema({
typeDefs: scalarTest,
resolvers: {
TestScalar: new GraphQLScalarType({
name: 'TestScalar',
description: undefined,
serialize: value => (value as string).slice(1),
parseValue: value => `_${value}`,
parseLiteral: (ast: any) => `_${ast.value}`,
}),
Query: {
testingScalar(parent, args) {
return {
value: args.input[0] === '_' ? args.input : null
};
},
},
},
});

before(() => {
schema = transformSchema(scalarSchema, []);
});
it('should work', async () => {
const result = await graphql(
schema,
`
query($input: TestScalar) {
testingScalar(input: $input) {
value
}
}
`,
{},
{},
{
input: 'test',
},
);

expect(result).to.deep.equal({
data: {
testingScalar: {
value: 'test',
},
},
});
});
});

describe('rename type', () => {
let schema: GraphQLSchema;
before(() => {
Expand Down

0 comments on commit a666aed

Please sign in to comment.