Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/birkir/graphql-mst
Convert GraphQL to mobx-state-tree models
https://github.com/birkir/graphql-mst
converter graphql mobx mobx-state-tree mst parser typescript
Last synced: 13 days ago
JSON representation
Convert GraphQL to mobx-state-tree models
- Host: GitHub
- URL: https://github.com/birkir/graphql-mst
- Owner: birkir
- License: mit
- Created: 2019-02-06T23:41:32.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-07T18:47:57.000Z (almost 6 years ago)
- Last Synced: 2024-07-31T07:19:01.576Z (3 months ago)
- Topics: converter, graphql, mobx, mobx-state-tree, mst, parser, typescript
- Language: TypeScript
- Size: 254 KB
- Stars: 23
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome - graphql-mst - Convert GraphQL to mobx-state-tree models (TypeScript)
README
[![npm downloads](https://img.shields.io/npm/dt/graphql-mst.svg)](https://www.npmjs.com/package/graphql-mst)
[![npm](https://img.shields.io/npm/v/graphql-mst.svg?maxAge=2592000)](https://www.npmjs.com/package/graphql-mst)
[![codecov](https://codecov.io/gh/birkir/graphql-mst/branch/master/graph/badge.svg)](https://codecov.io/gh/birkir/graphql-mst)
[![CircleCI](https://circleci.com/gh/birkir/graphql-mst.svg?style=shield)](https://circleci.com/gh/birkir/graphql-mst)
[![MIT license](https://img.shields.io/github/license/birkir/graphql-mst.svg)](https://opensource.org/licenses/MIT)# graphql-mst
Convert GraphQL Schema to mobx-state-tree models.
See demos in [tests folder](https://github.com/birkir/graphql-mst/blob/master/__tests__/index.ts)
### Installing
```bash
yarn add graphql-mst
# or
npm install graphql-mst
```### Usage
```ts
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 }],
});
```#### Identifiers
```ts
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 }
```### TODO and thoughts
- Configure map type instead of array type
- Default values for arguments as `types.optional`
- reference types?
- Date scalar? Custom scalar?