Convert GraphQL Schema to mobx-state-tree models.
See demos in tests folder
yarn add graphql-mst
# or
npm install graphql-mst
import { generateFromSchema } from 'graphql-mst';
const schema = `
type Foo {
a: String
b: Int
}
type Bar {
c: [Foo]
}
`;
const { Foo, Bar } = generateFromSchema(schema);
const foo = Foo.create({
a: 'Hello',
b: 10,
});
const bar = Bar.create({
c: [foo, { a: 'World', b: 20 }],
});
const schema = `
type Foo {
userId: ID!
fooId: ID!
}
`;
const config = {
Foo: {
identifier: 'fooId', // this will be used as identifier for model 'Foo'
},
};
const { Foo } = generateFromSchema(schema, config);
const lookup = types
.model({ items: types.map(Foo) })
.actions(self => ({ add: item => self.items.put(item) }))
.create({ items: {} });
lookup.put({ userId: 10, fooId: 1 });
lookup.put({ userId: 20, fooId: 2 });
lookup.items.get(1); // { userId: 10, fooId: 1 }
lookup.items.get(2); // { userId: 20, fooId: 2 }
- Configure map type instead of array type
- Default values for arguments as
types.optional
- reference types?
- Date scalar? Custom scalar?