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

Commit

Permalink
fix(stitching): add test
Browse files Browse the repository at this point in the history
RenameObjectFields and RenameRootFields should work when used together.
  • Loading branch information
yaacovCR committed Nov 27, 2019
1 parent 563cdce commit 372dcdd
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions src/test/testAlternateMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,102 @@ describe('transform object fields', () => {
});
});

describe('rename object fields', () => {
it('should work', async () => {
const ITEM = {
id: '123',
camel_case: "I'm a camel!",
};

const itemSchema = makeExecutableSchema({
typeDefs: `
type Item {
id: ID!
camel_case: String
}
type ItemConnection {
edges: [ItemEdge!]!
}
type ItemEdge {
node: Item!
}
type Query {
item: Item
allItems: ItemConnection!
}
`,
resolvers: {
Query: {
item: () => ITEM,
allItems: () => ({
edges: [
{
node: ITEM
}
]
})
}
}
});

const schema = transformSchema(itemSchema, [
new RenameObjectFields((_typeName, fieldName) => {
if (fieldName === 'camel_case') {
return 'camelCase';
}
return fieldName;
}),
new RenameRootFields((_operation, fieldName) => {
if (fieldName === 'allItems') {
return 'items';
}
return fieldName;
}),
]);

const result = await graphql(
schema,
`
query {
item {
id
camelCase
}
items {
edges {
node {
id
camelCase
}
}
}
}
`,
{},
{},
{
pid: 'p1',
},
);

const TRANSFORMED_ITEM = {
id: '123',
camelCase: "I'm a camel!",
};

expect(result).to.deep.equal({
data: {
item: TRANSFORMED_ITEM,
items: {
edges: [{
node: TRANSFORMED_ITEM,
}],
},
},
});
});
});

describe('filter and rename object fields', () => {
let transformedPropertySchema: GraphQLSchema;

Expand Down

0 comments on commit 372dcdd

Please sign in to comment.