graphql-codegen-fast-check
v0.0.2
Published
## What?
Downloads
235
Readme
GraphQL Codegen for Fast Check
What?
GraphQL Code Generator lets you generate
code from a GraphQL
schema. It is commonly used to create Typescript
types to ensure the consuming program agrees with the data it is receiving.
Fast-check is a Property Testing
framework for Typescript
/ Javascript
. It allows testing properties of a
program using arbitrarily generated data. Fast-check
uses arbitrary
s to
create data, that is, descriptions of the data we need to create.
Say we have this datatype...
// our datatype
interface Person {
name: string;
age: number;
}
...the code to make the fast-check
arbitrary
would look like:
import * as fc from "fast-check";
const personArbitrary = fc.record({
name: fc.string(),
age: fc.integer()
});
This can then be used in property tests or as generators to create sample test data. The problem is that writing them all by hand and keeping them up to date with your datatypes is a pain.
This library
This library is a plugin for GraphQL Code Generator
that creates fast-check
Arbitrary
s for your schema data types.
How to use
ahem
What's working?
[X] Object types [X] Built-in Scalar types [X] Enumeration types [X] Type modifiers (1) [ ] Custom Scalar types (2) [X] Union types [X] Interface types (3) [ ] Input types (4) [ ] Documents (5)
- Currently lists work but we ignore the nullable / non-nullable distinction. Everything is non-nullable for now, this will come soon.
- Custom Scalar types are defined outside the schema, frustratingly. For now
they all emit a
string
, the plan is to allow the config to specify a file to override these with the user's ownarbitrary
instances. - These "work" but need to check whether they are actually correct
- Currently these just output a
string
(why? don't know) -fast-check
has afunc
arbitrary
which should make this fairly straightforward to implement. - I haven't even thought about tackling this part yet.
Inspiration
Thanks to fast-check-io-ts
for showing me that making arbitrary
instances should be easy.