Last active
March 24, 2021 20:30
-
-
Save maapteh/ac8d25be2b44ae175a41259b859d9bfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'reflect-metadata'; | |
import { | |
createModule, | |
testkit, | |
gql, | |
} from 'graphql-modules'; | |
export const _hackKeepExtendWorking = { | |
typeDefs: gql` | |
type Query { | |
foo: String! | |
} | |
type Mutation { | |
bar: String! | |
} | |
`, | |
resolvers: { | |
Query: { | |
foo() { | |
return { | |
name: 'Bar', | |
}; | |
}, | |
}, | |
Mutation: { | |
bar() { | |
return { | |
name: 'Foo', | |
}; | |
}, | |
}, | |
}, | |
}; | |
describe('testModule', () => { | |
const ListModule = createModule({ | |
id: 'list', | |
typeDefs: gql` | |
extend type Query { | |
list: List! | |
} | |
type List { | |
id: ID! | |
title: String! | |
} | |
`, | |
resolvers: { | |
Query: { | |
list() { | |
return { | |
id: '123-456-789', | |
title: 'foo' | |
}; | |
}, | |
} | |
} | |
}); | |
const ProductModule = createModule({ | |
id: 'product', | |
typeDefs: gql` | |
extend type Query { | |
product: Product! | |
} | |
type Product { | |
id: ID! | |
} | |
# this module extends on list | |
extend type List { | |
product: Product! | |
} | |
`, | |
resolvers: { | |
Query: { | |
product() { | |
return { | |
id: '42', | |
}; | |
}, | |
}, | |
List: { | |
product: () => { | |
return { | |
id: '42', | |
}; | |
} | |
} | |
} | |
}); | |
test('should not throw error (it will)', () => { | |
expect(() => | |
testkit.testModule(ProductModule, { | |
replaceExtensions: true, | |
inheritTypeDefs: [ | |
ListModule, | |
], | |
}) | |
).not.toThrow(); | |
}); | |
test('with hack i can make it work', async () => { | |
const app = testkit.testModule(ProductModule, { | |
..._hackKeepExtendWorking, | |
inheritTypeDefs: [ | |
ListModule, | |
], | |
}) | |
const result = await testkit.execute(app, { | |
document: gql` | |
query product { | |
product { | |
id | |
} | |
} | |
` | |
}); | |
expect(result.data.product.id).toBe('42'); | |
}); | |
}); |
made it a runnable one at: https://codesandbox.io/s/github/maapteh/sandbox-feature-request?file=/test.ts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
results in:
what i need as testkit option is to replace extensions on Queries/Mutations/Subscriptions but leave extending on eachother types in place. Else i have to hack it to run it, now i add a query and mutation so the extension gives no problems.