├── .babelrc
├── .editorconfig
├── .github
├── FUNDING.yml
└── workflows
│ └── build-and-test.yml
├── .gitignore
├── .husky
└── pre-commit
├── .prettierignore
├── .prettierrc
├── .vscode
└── settings.json
├── .yarn
├── patches
│ └── react-scripts-npm-5.0.1-d06bd2d5ad.patch
└── releases
│ └── yarn-3.2.1.cjs
├── .yarnrc.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── examples
├── 1-getting-started
│ ├── .gitignore
│ ├── README.md
│ ├── package.json
│ ├── public
│ │ └── index.html
│ ├── src
│ │ ├── app
│ │ │ ├── Home.tsx
│ │ │ ├── components
│ │ │ │ ├── Error.tsx
│ │ │ │ ├── Loading.tsx
│ │ │ │ ├── ServerString.tsx
│ │ │ │ ├── Todo.tsx
│ │ │ │ └── index.ts
│ │ │ ├── index.css
│ │ │ ├── index.tsx
│ │ │ └── models
│ │ │ │ ├── ModelBase.ts
│ │ │ │ ├── RootStore.base.ts
│ │ │ │ ├── RootStore.ts
│ │ │ │ ├── TodoModel.base.ts
│ │ │ │ ├── TodoModel.ts
│ │ │ │ ├── index.ts
│ │ │ │ └── reactUtils.ts
│ │ └── server
│ │ │ ├── index.js
│ │ │ └── schema.js
│ └── tsconfig.json
├── 2-scaffolding
│ ├── README.md
│ ├── graphql-schema.json
│ ├── mst-gql.config.js
│ ├── package.json
│ ├── src
│ │ └── models
│ │ │ ├── AttackModel.base.ts
│ │ │ ├── AttackModel.ts
│ │ │ ├── ModelBase.ts
│ │ │ ├── PokemonAttackModel.base.ts
│ │ │ ├── PokemonAttackModel.ts
│ │ │ ├── PokemonDimensionModel.base.ts
│ │ │ ├── PokemonDimensionModel.ts
│ │ │ ├── PokemonEvolutionRequirementModel.base.ts
│ │ │ ├── PokemonEvolutionRequirementModel.ts
│ │ │ ├── PokemonModel.base.ts
│ │ │ ├── PokemonModel.ts
│ │ │ ├── RootStore.base.ts
│ │ │ ├── RootStore.ts
│ │ │ ├── index.ts
│ │ │ └── reactUtils.ts
│ └── tsconfig.json
├── 3-twitter-clone
│ ├── .gitignore
│ ├── README.md
│ ├── package.json
│ ├── public
│ │ └── index.html
│ └── src
│ │ ├── app
│ │ ├── avatars
│ │ │ ├── chuck.jpg
│ │ │ └── michel.jpg
│ │ ├── components
│ │ │ ├── Composer.tsx
│ │ │ ├── Home.tsx
│ │ │ ├── Message.tsx
│ │ │ ├── MessageWall.tsx
│ │ │ ├── Profile.tsx
│ │ │ ├── Replies.tsx
│ │ │ └── utils
│ │ │ │ ├── Error.tsx
│ │ │ │ ├── Loading.tsx
│ │ │ │ ├── index.ts
│ │ │ │ └── spinner.gif
│ │ ├── index.css
│ │ ├── index.tsx
│ │ ├── models
│ │ │ ├── BaseIDModelSelector.ts
│ │ │ ├── MessageModel.base.ts
│ │ │ ├── MessageModel.ts
│ │ │ ├── ModelBase.ts
│ │ │ ├── RootStore.base.ts
│ │ │ ├── RootStore.ts
│ │ │ ├── SearchResultModelSelector.ts
│ │ │ ├── UserModel.base.ts
│ │ │ ├── UserModel.ts
│ │ │ ├── index.ts
│ │ │ └── reactUtils.ts
│ │ └── tsconfig.json
│ │ └── server
│ │ ├── db
│ │ └── initial.json
│ │ ├── index.ts
│ │ ├── models
│ │ ├── MessageModel.base.ts
│ │ ├── MessageModel.ts
│ │ ├── ModelBase.ts
│ │ ├── ReplyModel.base.ts
│ │ ├── ReplyModel.ts
│ │ ├── RootStore.base.ts
│ │ ├── RootStore.ts
│ │ ├── UserModel.base.ts
│ │ ├── UserModel.ts
│ │ ├── index.ts
│ │ └── reactUtils.ts
│ │ ├── schema.graphql
│ │ ├── schema.ts
│ │ └── tsconfig.json
├── 4-apollo-tutorial
│ ├── README.md
│ ├── client
│ │ ├── .env
│ │ ├── .env.example
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── apollo.config.js
│ │ ├── demo_schema.json
│ │ ├── package.json
│ │ ├── public
│ │ │ ├── favicon.ico
│ │ │ ├── index.html
│ │ │ └── manifest.json
│ │ └── src
│ │ │ ├── assets
│ │ │ ├── curve.svg
│ │ │ ├── icons
│ │ │ │ ├── cart.svg
│ │ │ │ ├── exit.svg
│ │ │ │ ├── home.svg
│ │ │ │ └── profile.svg
│ │ │ ├── images
│ │ │ │ ├── badge-1.png
│ │ │ │ ├── badge-2.png
│ │ │ │ ├── badge-3.png
│ │ │ │ ├── dog-1.png
│ │ │ │ ├── dog-2.png
│ │ │ │ ├── dog-3.png
│ │ │ │ ├── galaxy.jpg
│ │ │ │ ├── iss.jpg
│ │ │ │ ├── moon.jpg
│ │ │ │ └── space.jpg
│ │ │ ├── logo.svg
│ │ │ └── rocket.svg
│ │ │ ├── components
│ │ │ ├── __tests__
│ │ │ │ ├── button.js
│ │ │ │ ├── footer.js
│ │ │ │ ├── header.js
│ │ │ │ ├── launch-detail.js
│ │ │ │ ├── launch-tile.js
│ │ │ │ ├── loading.js
│ │ │ │ ├── login-form.js
│ │ │ │ ├── menu-item.js
│ │ │ │ └── page-container.js
│ │ │ ├── button.js
│ │ │ ├── footer.js
│ │ │ ├── header.js
│ │ │ ├── index.js
│ │ │ ├── launch-detail.js
│ │ │ ├── launch-tile.js
│ │ │ ├── loading.js
│ │ │ ├── login-form.js
│ │ │ ├── menu-item.js
│ │ │ └── page-container.js
│ │ │ ├── containers
│ │ │ ├── __tests__
│ │ │ │ ├── action-button.js
│ │ │ │ ├── book-trips.js
│ │ │ │ ├── cart-item.js
│ │ │ │ └── logout-button.js
│ │ │ ├── action-button.js
│ │ │ ├── book-trips.js
│ │ │ ├── cart-item.js
│ │ │ ├── index.js
│ │ │ └── logout-button.js
│ │ │ ├── index.js
│ │ │ ├── models
│ │ │ ├── LaunchConnectionModel.base.js
│ │ │ ├── LaunchConnectionModel.js
│ │ │ ├── LaunchModel.base.js
│ │ │ ├── LaunchModel.js
│ │ │ ├── MissionModel.base.js
│ │ │ ├── MissionModel.js
│ │ │ ├── ModelBase.js
│ │ │ ├── PatchSizeEnum.js
│ │ │ ├── RocketModel.base.js
│ │ │ ├── RocketModel.js
│ │ │ ├── RootStore.base.js
│ │ │ ├── RootStore.js
│ │ │ ├── UserModel.base.js
│ │ │ ├── UserModel.js
│ │ │ ├── index.js
│ │ │ └── reactUtils.js
│ │ │ ├── pages
│ │ │ ├── __tests__
│ │ │ │ ├── cart.js
│ │ │ │ ├── launch.js
│ │ │ │ ├── launches.js
│ │ │ │ ├── login.js
│ │ │ │ └── profile.js
│ │ │ ├── cart.js
│ │ │ ├── index.js
│ │ │ ├── launch.js
│ │ │ ├── launches.js
│ │ │ ├── login.js
│ │ │ └── profile.js
│ │ │ ├── styles.js
│ │ │ └── test-utils.js
│ └── server
│ │ ├── .env.example
│ │ ├── apollo.config.js
│ │ ├── now.json
│ │ ├── package.json
│ │ ├── src
│ │ ├── __tests__
│ │ │ ├── __snapshots__
│ │ │ │ ├── e2e.js.snap
│ │ │ │ └── integration.js.snap
│ │ │ ├── __utils.js
│ │ │ ├── e2e.js
│ │ │ ├── integration.js
│ │ │ ├── resolvers.mission.js
│ │ │ ├── resolvers.mutation.js
│ │ │ ├── resolvers.query.js
│ │ │ └── resolvers.user.js
│ │ ├── datasources
│ │ │ ├── __tests__
│ │ │ │ ├── launch.js
│ │ │ │ └── user.js
│ │ │ ├── launch.js
│ │ │ └── user.js
│ │ ├── engine-demo.js
│ │ ├── index.js
│ │ ├── resolvers.js
│ │ ├── schema.js
│ │ └── utils.js
│ │ └── store.sqlite
├── 5-nextjs
│ ├── README.md
│ ├── components
│ │ ├── todos.tsx
│ │ └── users.tsx
│ ├── mst-gql.config.js
│ ├── next-env.d.ts
│ ├── package.json
│ ├── pages
│ │ ├── _app.tsx
│ │ ├── index.tsx
│ │ └── other.tsx
│ ├── server
│ │ ├── index.js
│ │ ├── schema.js
│ │ └── store.js
│ ├── src
│ │ └── models
│ │ │ ├── ModelBase.ts
│ │ │ ├── RootStore.base.ts
│ │ │ ├── RootStore.ts
│ │ │ ├── TodoModel.base.ts
│ │ │ ├── TodoModel.ts
│ │ │ ├── UserModel.base.ts
│ │ │ ├── UserModel.ts
│ │ │ ├── index.ts
│ │ │ └── reactUtils.ts
│ └── tsconfig.json
└── 6-scaffolding-ts-hasura
│ ├── README.md
│ ├── mst-gql.config.js
│ ├── package.json
│ ├── schema.graphql
│ ├── src
│ └── models
│ │ ├── ChoicesAggregateFieldsModel.base.ts
│ │ ├── ChoicesAggregateFieldsModel.ts
│ │ ├── ChoicesAggregateModel.base.ts
│ │ ├── ChoicesAggregateModel.ts
│ │ ├── ChoicesAvgFieldsModel.base.ts
│ │ ├── ChoicesAvgFieldsModel.ts
│ │ ├── ChoicesConstraintEnum.ts
│ │ ├── ChoicesMaxFieldsModel.base.ts
│ │ ├── ChoicesMaxFieldsModel.ts
│ │ ├── ChoicesMinFieldsModel.base.ts
│ │ ├── ChoicesMinFieldsModel.ts
│ │ ├── ChoicesModel.base.ts
│ │ ├── ChoicesModel.ts
│ │ ├── ChoicesMutationResponseModel.base.ts
│ │ ├── ChoicesMutationResponseModel.ts
│ │ ├── ChoicesSelectColumnEnum.ts
│ │ ├── ChoicesStddevFieldsModel.base.ts
│ │ ├── ChoicesStddevFieldsModel.ts
│ │ ├── ChoicesStddevPopFieldsModel.base.ts
│ │ ├── ChoicesStddevPopFieldsModel.ts
│ │ ├── ChoicesStddevSampFieldsModel.base.ts
│ │ ├── ChoicesStddevSampFieldsModel.ts
│ │ ├── ChoicesSumFieldsModel.base.ts
│ │ ├── ChoicesSumFieldsModel.ts
│ │ ├── ChoicesUpdateColumnEnum.ts
│ │ ├── ChoicesVarPopFieldsModel.base.ts
│ │ ├── ChoicesVarPopFieldsModel.ts
│ │ ├── ChoicesVarSampFieldsModel.base.ts
│ │ ├── ChoicesVarSampFieldsModel.ts
│ │ ├── ChoicesVarianceFieldsModel.base.ts
│ │ ├── ChoicesVarianceFieldsModel.ts
│ │ ├── ConflictActionEnum.ts
│ │ ├── ModelBase.ts
│ │ ├── MutationRootModel.base.ts
│ │ ├── MutationRootModel.ts
│ │ ├── OrderByEnum.ts
│ │ ├── PollsAggregateFieldsModel.base.ts
│ │ ├── PollsAggregateFieldsModel.ts
│ │ ├── PollsAggregateModel.base.ts
│ │ ├── PollsAggregateModel.ts
│ │ ├── PollsAvgFieldsModel.base.ts
│ │ ├── PollsAvgFieldsModel.ts
│ │ ├── PollsConstraintEnum.ts
│ │ ├── PollsMaxFieldsModel.base.ts
│ │ ├── PollsMaxFieldsModel.ts
│ │ ├── PollsMinFieldsModel.base.ts
│ │ ├── PollsMinFieldsModel.ts
│ │ ├── PollsModel.base.ts
│ │ ├── PollsModel.ts
│ │ ├── PollsMutationResponseModel.base.ts
│ │ ├── PollsMutationResponseModel.ts
│ │ ├── PollsSelectColumnEnum.ts
│ │ ├── PollsStddevFieldsModel.base.ts
│ │ ├── PollsStddevFieldsModel.ts
│ │ ├── PollsStddevPopFieldsModel.base.ts
│ │ ├── PollsStddevPopFieldsModel.ts
│ │ ├── PollsStddevSampFieldsModel.base.ts
│ │ ├── PollsStddevSampFieldsModel.ts
│ │ ├── PollsSumFieldsModel.base.ts
│ │ ├── PollsSumFieldsModel.ts
│ │ ├── PollsUpdateColumnEnum.ts
│ │ ├── PollsVarPopFieldsModel.base.ts
│ │ ├── PollsVarPopFieldsModel.ts
│ │ ├── PollsVarSampFieldsModel.base.ts
│ │ ├── PollsVarSampFieldsModel.ts
│ │ ├── PollsVarianceFieldsModel.base.ts
│ │ ├── PollsVarianceFieldsModel.ts
│ │ ├── QueryRootModel.base.ts
│ │ ├── QueryRootModel.ts
│ │ ├── RootStore.base.ts
│ │ ├── RootStore.ts
│ │ ├── SubscriptionRootModel.base.ts
│ │ ├── SubscriptionRootModel.ts
│ │ ├── index.ts
│ │ └── reactUtils.ts
│ └── tsconfig.json
├── generator
├── config.js
├── generate.js
├── logger.js
├── mst-gql-scaffold.js
└── utilities.js
├── jest.config.js
├── package.json
├── src
├── MSTGQLObject.ts
├── MSTGQLStore.ts
├── Query.ts
├── createHttpClient.ts
├── deflateHelper.ts
├── localStorageMixin.ts
├── mergeHelper.ts
├── mst-gql.ts
├── queryBuilder.ts
├── react.tsx
├── utils.ts
└── withTypedRefs.ts
├── tests
├── config.test.js
├── cra-test
│ ├── .yarnrc.yml
│ ├── package.json
│ └── yarn.lock
├── generator
│ ├── __snapshots__
│ │ └── generate.test.js.snap
│ └── generate.test.js
├── lib
│ ├── abstractTypes
│ │ ├── abstractTypes.test.js
│ │ ├── models
│ │ │ ├── BookModel.base.js
│ │ │ ├── BookModel.js
│ │ │ ├── ModelBase.js
│ │ │ ├── MovieModel.base.js
│ │ │ ├── MovieModel.js
│ │ │ ├── OrganizationModel.base.js
│ │ │ ├── OrganizationModel.js
│ │ │ ├── OwnerModelSelector.js
│ │ │ ├── RepoModel.base.js
│ │ │ ├── RepoModel.js
│ │ │ ├── RootStore.base.js
│ │ │ ├── RootStore.js
│ │ │ ├── SearchItemModelSelector.js
│ │ │ ├── SearchResultModel.base.js
│ │ │ ├── SearchResultModel.js
│ │ │ ├── UserModel.base.js
│ │ │ ├── UserModel.js
│ │ │ ├── index.js
│ │ │ └── reactUtils.js
│ │ └── schema.graphql
│ ├── todos
│ │ ├── __snapshots__
│ │ │ └── todostore.test.js.snap
│ │ ├── models
│ │ │ ├── ModelBase.js
│ │ │ ├── RootStore.base.js
│ │ │ ├── RootStore.js
│ │ │ ├── TodoModel.base.js
│ │ │ ├── TodoModel.js
│ │ │ ├── index.js
│ │ │ └── reactUtils.js
│ │ ├── todos.graphql
│ │ └── todostore.test.js
│ └── unionTypes
│ │ ├── models
│ │ ├── BasicTodoModel.base.js
│ │ ├── BasicTodoModel.js
│ │ ├── FancyTodoModel.base.js
│ │ ├── FancyTodoModel.js
│ │ ├── ModelBase.js
│ │ ├── RootStore.base.js
│ │ ├── RootStore.js
│ │ ├── TodoListModel.base.js
│ │ ├── TodoListModel.js
│ │ ├── TodoModelSelector.js
│ │ ├── index.js
│ │ └── reactUtils.js
│ │ ├── todos.graphql
│ │ └── todostore.test.js
└── vite-app-test
│ └── test-vite-app.sh
├── tsconfig.json
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["@babel/preset-env", { "targets": { "node": "current" } }],
4 | "@babel/preset-typescript"
5 | ],
6 | "plugins": [
7 | ["@babel/plugin-proposal-decorators", { "legacy": true }],
8 | ["@babel/plugin-proposal-class-properties", { "loose": true }],
9 | ["@babel/plugin-syntax-jsx", {}]
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | insert_final_newline = true
6 |
7 | [*.{js,json,yml}]
8 | charset = utf-8
9 | indent_style = space
10 | indent_size = 2
11 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | #github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | #patreon: # Replace with a single Patreon username
5 | #open_collective: # Replace with a single Open Collective username
6 | #ko_fi: # Replace with a single Ko-fi username
7 | #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | #liberapay: # Replace with a single Liberapay username
10 | #issuehunt: # Replace with a single IssueHunt username
11 | #otechie: # Replace with a single Otechie username
12 | #custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.github/workflows/build-and-test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 | on:
3 | pull_request: {}
4 | workflow_dispatch:
5 |
6 | jobs:
7 | test:
8 | name: Tests
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: Checkout Source Code
12 | uses: actions/checkout@v4
13 | with:
14 | fetch-depth: 0
15 | lfs: true
16 |
17 | - name: Install Node.js
18 | uses: actions/setup-node@v4
19 | with:
20 | node-version: '18'
21 | cache: 'yarn'
22 |
23 | - name: Install Dependencies
24 | run: yarn install --immutable
25 |
26 | - name: Check Formatting
27 | run: yarn format --check
28 |
29 | - name: Build mst-gql
30 | run: yarn build
31 |
32 | - name: Test mst-gql
33 | run: yarn test:mst-gql
34 |
35 | - name: Test Example 2 (Scaffolding)
36 | run: yarn test:example-2
37 |
38 | - name: Test Example 6 (Hasura)
39 | run: yarn test:example-6
40 |
41 | # - name: Test e2e vite app
42 | # run: yarn test:vite
43 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | yarn pretty-quick --staged
2 | yarn syncpack format
3 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # ignore a wide range of support files
2 | .*
3 |
4 | # build files
5 | dist/
6 |
7 | # test files
8 | __snapshots__
9 | tests/test-cra.sh
10 | *.sqlite
11 |
12 | # mst-gql generated files
13 | **/models/index.*
14 | **/models/reactUtils.*
15 | **/models/*.base.*
16 | **/models/*Enum.*
17 | **/models/*ModelSelector.*
18 |
19 | # yarn
20 | yarn.lock
21 | yarn-error.log
22 |
23 | # images
24 | *.png
25 | *.jpg
26 | *.svg
27 | *.gif
28 | *.ico
29 |
30 | # etc
31 | LICENSE
32 | *.txt
33 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "bracketSpacing": true,
3 | "printWidth": 80,
4 | "proseWrap": "never",
5 | "requirePragma": false,
6 | "semi": false,
7 | "singleQuote": false,
8 | "tabWidth": 2,
9 | "trailingComma": "none",
10 | "useTabs": false,
11 | "overrides": [
12 | {
13 | "files": [".prettierrc", "*.json"],
14 | "options": {
15 | "printWidth": 200,
16 | "tabWidth": 2
17 | }
18 | }
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.tabSize": 2,
3 | "eslint.enable": false,
4 | "cSpell.enabled": false,
5 | "typescript.tsdk": "node_modules/typescript/lib"
6 | }
7 |
--------------------------------------------------------------------------------
/.yarnrc.yml:
--------------------------------------------------------------------------------
1 | defaultSemverRangePrefix: ""
2 |
3 | nodeLinker: node-modules
4 |
5 | npmPublishRegistry: "https://registry.yarnpkg.com"
6 |
7 | yarnPath: .yarn/releases/yarn-3.2.1.cjs
8 |
9 | enableGlobalCache: true
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 MobX
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/examples/1-getting-started/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .build
3 | lib
4 | .cache
--------------------------------------------------------------------------------
/examples/1-getting-started/README.md:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | This example is "borrowed" from the awesome urql repository [here](https://github.com/FormidableLabs/urql/tree/master/examples/1-getting-started).
4 |
5 | This example demonstrates a simple mst-gql project (without scaffolding set up)
6 |
7 | ## Usage
8 |
9 | #### 0. install `mst-gql` dependencies (within the parent `mst-gql` directory)
10 |
11 | ```bash
12 | yarn
13 | ```
14 |
15 | #### 1. Install dependencies (within this example's folder)
16 |
17 | ```bash
18 | yarn
19 | ```
20 |
21 | #### 2. Start server
22 |
23 | ```bash
24 | yarn start
25 | ```
26 |
27 | #### 3. Open browser
28 |
29 | Navigate to example at [http://localhost:3000/](http://localhost:3000/).
30 |
--------------------------------------------------------------------------------
/examples/1-getting-started/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@mst-gql/getting-started",
3 | "license": "MIT",
4 | "version": "1.0.0",
5 | "scripts": {
6 | "scaffold": "node ../../generator/mst-gql-scaffold.js --roots Todo --outDir src/app/models/ --format ts http://localhost:3001/graphql",
7 | "start": "run-p start:server start:client",
8 | "start:client": "wait-port 3001 && yarn scaffold && parcel serve -p 3000 public/index.html",
9 | "start:server": "node ./src/server/index.js",
10 | "type-check": "tsc --noEmit",
11 | "type-check:watch": "yarn type-check -- --watch"
12 | },
13 | "dependencies": {
14 | "apollo-server-express": "^2.18.0",
15 | "arg": "^5.0.2",
16 | "cors": "^2.8.5",
17 | "express": "^4.17.1",
18 | "graphql": "15.8.0",
19 | "graphql-playground-middleware-express": "^1.7.21",
20 | "graphql-tag": "^2.12.6",
21 | "isomorphic-fetch": "^2.2.1",
22 | "jest": "^27.0.6",
23 | "mobx": "^6.10.2",
24 | "mobx-react": "^7.5.0",
25 | "mobx-state-tree": "^5.3.0",
26 | "mst-gql": "portal:../../",
27 | "react": "^18.2.0",
28 | "react-dom": "^18.2.0"
29 | },
30 | "devDependencies": {
31 | "@babel/core": "^7.14.3",
32 | "@types/jest": "^27.5.2",
33 | "@types/react": "^18.0.15",
34 | "@types/react-dom": "^18.0.6",
35 | "npm-run-all": "^4.1.5",
36 | "parcel": "^2.6.0",
37 | "typescript": "^4.7.3",
38 | "wait-port": "^0.2.9"
39 | },
40 | "private": true
41 | }
42 |
--------------------------------------------------------------------------------
/examples/1-getting-started/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | MST-GQL Getting Started Example
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/Home.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { observer } from "mobx-react-lite"
3 | import { useQuery } from "./models/reactUtils"
4 |
5 | import { Error, Loading, Todo } from "./components"
6 |
7 | export const Home = observer(() => {
8 | const { loading, error, data, query } = useQuery((store) =>
9 | store.queryTodos()
10 | )
11 | if (error) return {error.message}
12 | if (data)
13 | return (
14 | <>
15 |
16 | {data.todos.map((todo) => (
17 |
18 | ))}
19 |
20 | {loading ? (
21 |
22 | ) : (
23 |
24 | )}
25 | >
26 | )
27 | return
28 | })
29 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/components/Error.tsx:
--------------------------------------------------------------------------------
1 | import React, { FC } from "react"
2 |
3 | export const Error: FC = (props) => (
4 | <>
5 | Error
6 | Something went wrong
7 | Message: {props.children}
8 | >
9 | )
10 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/components/Loading.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | export const Loading = () => Loading...
4 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/components/ServerString.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { observer } from "mobx-react-lite"
3 | import { useQuery } from "../models/reactUtils"
4 |
5 | import { Error, Loading } from "./"
6 |
7 | export const ServerString = observer(() => {
8 | const { loading, error, data, query } = useQuery((store) =>
9 | store.queryStringFromServer({ string: "Todos" })
10 | )
11 | if (error) return {error.message}
12 | if (data) return <>{data.stringFromServer}>
13 | return
14 | })
15 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/components/Todo.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { observer } from "mobx-react-lite"
3 |
4 | import { TodoModelType } from "../models"
5 | import { useQuery } from "../models/reactUtils"
6 |
7 | export const Todo = observer(({ todo }: { todo: TodoModelType }) => {
8 | const { setQuery, loading, error } = useQuery(undefined)
9 |
10 | return (
11 | setQuery(todo.toggle())}>
12 | {todo.text}
13 | {error && Failed to update}
14 | {loading && (updating)}
15 |
16 | )
17 | })
18 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/components/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./Error"
2 | export * from "./Loading"
3 | export * from "./Todo"
4 | export * from "./ServerString"
5 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/index.css:
--------------------------------------------------------------------------------
1 | html {
2 | background: #488;
3 | font-family: sans-serif;
4 | }
5 |
6 | #root {
7 | width: 100%;
8 | display: flex;
9 | justify-content: center;
10 | }
11 |
12 | main {
13 | width: 400px;
14 | }
15 |
16 | h1 {
17 | color: #2d4a4a;
18 | }
19 |
20 | h4 {
21 | margin: 0;
22 | margin-bottom: 5px;
23 | }
24 |
25 | ul {
26 | list-style-type: none;
27 | padding: 0;
28 | }
29 |
30 | li {
31 | background: #fff;
32 | display: flex;
33 | justify-content: space-between;
34 | box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
35 | padding: 20px;
36 | margin: 20px 0;
37 | border-radius: 4px;
38 | }
39 |
40 | li span {
41 | color: #999;
42 | }
43 |
44 | .strikethrough {
45 | text-decoration: line-through;
46 | }
47 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import * as ReactDOM from "react-dom"
3 | import { createHttpClient } from "mst-gql"
4 |
5 | import "./index.css"
6 |
7 | import { RootStore } from "./models/RootStore"
8 | import { StoreContext } from "./models/reactUtils"
9 | import { Home } from "./Home"
10 | import { ServerString } from "./components"
11 |
12 | const rootStore = RootStore.create(undefined, {
13 | gqlHttpClient: createHttpClient("http://localhost:3001/graphql")
14 | })
15 |
16 | export const App: React.FC = () => (
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | )
26 |
27 | ReactDOM.render(, document.getElementById("root"))
28 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/models/ModelBase.ts:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/models/RootStore.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { RootStoreBase } from "./RootStore.base"
3 |
4 | export interface RootStoreType extends Instance {}
5 |
6 | export const RootStore = RootStoreBase.actions((self) => ({
7 | // This is an auto-generated example action.
8 | log() {
9 | console.log(JSON.stringify(self))
10 | }
11 | }))
12 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/models/TodoModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * TodoBase
13 | * auto generated base class for the model TodoModel.
14 | */
15 | export const TodoModelBase = ModelBase
16 | .named('Todo')
17 | .props({
18 | __typename: types.optional(types.literal("Todo"), "Todo"),
19 | id: types.identifier,
20 | text: types.union(types.undefined, types.null, types.string),
21 | complete: types.union(types.undefined, types.null, types.boolean),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class TodoModelSelector extends QueryBuilder {
30 | get id() { return this.__attr(`id`) }
31 | get text() { return this.__attr(`text`) }
32 | get complete() { return this.__attr(`complete`) }
33 | }
34 | export function selectFromTodo() {
35 | return new TodoModelSelector()
36 | }
37 |
38 | export const todoModelPrimitives = selectFromTodo().text.complete
39 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/models/TodoModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { TodoModelBase } from "./TodoModel.base"
3 | import { Query } from "mst-gql"
4 |
5 | /* The TypeScript type of an instance of TodoModel */
6 | export interface TodoModelType extends Instance {}
7 |
8 | /* A graphql query fragment builders for TodoModel */
9 | export {
10 | selectFromTodo,
11 | todoModelPrimitives,
12 | TodoModelSelector
13 | } from "./TodoModel.base"
14 |
15 | /**
16 | * TodoModel
17 | */
18 | export const TodoModel = TodoModelBase.actions((self) => ({
19 | toggle(): Query<{
20 | toggleTodo: TodoModelType
21 | }> {
22 | return self.store.mutateToggleTodo({ id: self.id }, undefined, () => {
23 | self.complete = !self.complete
24 | })
25 | }
26 | }))
27 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/models/index.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | export * from "./TodoModel"
6 | export * from "./RootStore"
7 | export * from "./reactUtils"
8 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/app/models/reactUtils.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { createStoreContext, createUseQueryHook } from "mst-gql"
6 | import * as React from "react"
7 | import { RootStoreType } from "./RootStore"
8 |
9 | export const StoreContext = createStoreContext(React)
10 |
11 | export const useQuery = createUseQueryHook(StoreContext, React)
12 |
--------------------------------------------------------------------------------
/examples/1-getting-started/src/server/index.js:
--------------------------------------------------------------------------------
1 | const { ApolloServer, graphiqlExpress } = require("apollo-server-express")
2 | const { createServer } = require("http")
3 | const { SubscriptionServer } = require("subscriptions-transport-ws")
4 | const expressPlayground =
5 | require("graphql-playground-middleware-express").default
6 | const express = require("express")
7 | const app = express()
8 | const cors = require("cors")
9 |
10 | const { typeDefs, resolvers } = require("./schema")
11 |
12 | const PORT = 3001
13 |
14 | const server = new ApolloServer({
15 | typeDefs,
16 | resolvers
17 | })
18 |
19 | server.applyMiddleware({ app })
20 |
21 | const webServer = createServer(app)
22 | server.installSubscriptionHandlers(webServer)
23 |
24 | const graphqlEndpoint = `http://localhost:${PORT}${server.graphqlPath}`
25 | const subscriptionEndpoint = `ws://localhost:${PORT}${server.subscriptionsPath}`
26 |
27 | app.use(cors())
28 | app.get(
29 | "/",
30 | expressPlayground({
31 | endpoint: graphqlEndpoint,
32 | subscriptionEndpoint: subscriptionEndpoint
33 | })
34 | )
35 |
36 | webServer.listen(PORT, () => {
37 | console.log(`🚀 Server ready at ${graphqlEndpoint}`)
38 | console.log(`🚀 Subscriptions ready at ${subscriptionEndpoint}`)
39 | })
40 |
--------------------------------------------------------------------------------
/examples/1-getting-started/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "esnext",
4 | "module": "commonjs",
5 | "allowSyntheticDefaultImports": true,
6 | "esModuleInterop": true,
7 | "strict": true,
8 | "lib": ["dom", "dom.iterable", "esnext"],
9 | "jsx": "react",
10 | "noEmit": true,
11 | "moduleResolution": "node",
12 | "skipLibCheck": true
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/README.md:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | ❗️Note that this example does not run a client or server, it just scaffolds the models.
4 |
5 | This example shows a minimal example of how to configure the code scaffolding, if you have some schema available somewhere.
6 |
7 | ## Usage
8 |
9 | #### 0. install `mst-gql` dependencies (within the parent `mst-gql` directory)
10 |
11 | ```bash
12 | yarn
13 | ```
14 |
15 | #### 1. Install dependencies (within this example's folder)
16 |
17 | ```bash
18 | yarn
19 | ```
20 |
21 | #### 2. Scaffold
22 |
23 | ```bash
24 | yarn start
25 | ```
26 |
27 | Runs the scaffolder and uses TypeScript to compile the generated sources.
28 |
29 | ```bash
30 | yarn download
31 | ```
32 |
33 | Re-fetches the graphql-schema from the demo endpoint (this might take a while). The schema definition is downloaded from: https://graphql-pokemon.now.sh/
34 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/mst-gql.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | force: true,
3 | format: "ts",
4 | input: "graphql-schema.json",
5 | outDir: "src/models",
6 | roots: ["Pokemon", "Attack"]
7 | }
8 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@mst-gql/scaffold-test-2",
3 | "scripts": {
4 | "build": "tsc",
5 | "download": "yarn dlx gql-sdl https://graphql-pokemon.now.sh/ --output graphql-schema.gql",
6 | "scaffold": "../../generator/mst-gql-scaffold.js",
7 | "start": "yarn scaffold && yarn build"
8 | },
9 | "dependencies": {
10 | "graphql": "^16.5.0",
11 | "graphql-request": "^4.3.0",
12 | "mobx": "^6.10.2",
13 | "mobx-state-tree": "^5.3.0",
14 | "mst-gql": "portal:../../"
15 | },
16 | "devDependencies": {
17 | "@types/react": "^18.0.15",
18 | "@types/react-dom": "^18.0.6",
19 | "react": "^18.2.0",
20 | "react-dom": "^18.2.0",
21 | "typescript": "^4.7.3"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/AttackModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { AttackModelBase } from "./AttackModel.base"
3 |
4 | /* The TypeScript type of an instance of AttackModel */
5 | export interface AttackModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for AttackModel */
8 | export {
9 | selectFromAttack,
10 | attackModelPrimitives,
11 | AttackModelSelector
12 | } from "./AttackModel.base"
13 |
14 | /**
15 | * AttackModel
16 | *
17 | * Represents a Pokémon's attack types
18 | */
19 | export const AttackModel = AttackModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/ModelBase.ts:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/PokemonAttackModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PokemonAttackModelBase } from "./PokemonAttackModel.base"
3 |
4 | /* The TypeScript type of an instance of PokemonAttackModel */
5 | export interface PokemonAttackModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PokemonAttackModel */
9 | export {
10 | selectFromPokemonAttack,
11 | pokemonAttackModelPrimitives,
12 | PokemonAttackModelSelector
13 | } from "./PokemonAttackModel.base"
14 |
15 | /**
16 | * PokemonAttackModel
17 | *
18 | * Represents a Pokémon's attack types
19 | */
20 | export const PokemonAttackModel = PokemonAttackModelBase.actions((self) => ({
21 | // This is an auto-generated example action.
22 | log() {
23 | console.log(JSON.stringify(self))
24 | }
25 | }))
26 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/PokemonDimensionModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * PokemonDimensionBase
13 | * auto generated base class for the model PokemonDimensionModel.
14 | *
15 | * Represents a Pokémon's dimensions
16 | */
17 | export const PokemonDimensionModelBase = ModelBase
18 | .named('PokemonDimension')
19 | .props({
20 | __typename: types.optional(types.literal("PokemonDimension"), "PokemonDimension"),
21 | /** The minimum value of this dimension */
22 | minimum: types.union(types.undefined, types.null, types.string),
23 | /** The maximum value of this dimension */
24 | maximum: types.union(types.undefined, types.null, types.string),
25 | })
26 | .views(self => ({
27 | get store() {
28 | return self.__getStore()
29 | }
30 | }))
31 |
32 | export class PokemonDimensionModelSelector extends QueryBuilder {
33 | get minimum() { return this.__attr(`minimum`) }
34 | get maximum() { return this.__attr(`maximum`) }
35 | }
36 | export function selectFromPokemonDimension() {
37 | return new PokemonDimensionModelSelector()
38 | }
39 |
40 | export const pokemonDimensionModelPrimitives = selectFromPokemonDimension().minimum.maximum
41 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/PokemonDimensionModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PokemonDimensionModelBase } from "./PokemonDimensionModel.base"
3 |
4 | /* The TypeScript type of an instance of PokemonDimensionModel */
5 | export interface PokemonDimensionModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PokemonDimensionModel */
9 | export {
10 | selectFromPokemonDimension,
11 | pokemonDimensionModelPrimitives,
12 | PokemonDimensionModelSelector
13 | } from "./PokemonDimensionModel.base"
14 |
15 | /**
16 | * PokemonDimensionModel
17 | *
18 | * Represents a Pokémon's dimensions
19 | */
20 | export const PokemonDimensionModel = PokemonDimensionModelBase.actions(
21 | (self) => ({
22 | // This is an auto-generated example action.
23 | log() {
24 | console.log(JSON.stringify(self))
25 | }
26 | })
27 | )
28 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/PokemonEvolutionRequirementModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PokemonEvolutionRequirementModelBase } from "./PokemonEvolutionRequirementModel.base"
3 |
4 | /* The TypeScript type of an instance of PokemonEvolutionRequirementModel */
5 | export interface PokemonEvolutionRequirementModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PokemonEvolutionRequirementModel */
9 | export {
10 | selectFromPokemonEvolutionRequirement,
11 | pokemonEvolutionRequirementModelPrimitives,
12 | PokemonEvolutionRequirementModelSelector
13 | } from "./PokemonEvolutionRequirementModel.base"
14 |
15 | /**
16 | * PokemonEvolutionRequirementModel
17 | *
18 | * Represents a Pokémon's requirement to evolve
19 | */
20 | export const PokemonEvolutionRequirementModel =
21 | PokemonEvolutionRequirementModelBase.actions((self) => ({
22 | // This is an auto-generated example action.
23 | log() {
24 | console.log(JSON.stringify(self))
25 | }
26 | }))
27 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/PokemonModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PokemonModelBase } from "./PokemonModel.base"
3 |
4 | /* The TypeScript type of an instance of PokemonModel */
5 | export interface PokemonModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for PokemonModel */
8 | export {
9 | selectFromPokemon,
10 | pokemonModelPrimitives,
11 | PokemonModelSelector
12 | } from "./PokemonModel.base"
13 |
14 | /**
15 | * PokemonModel
16 | *
17 | * Represents a Pokémon
18 | */
19 | export const PokemonModel = PokemonModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/RootStore.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { RootStoreBase } from "./RootStore.base"
3 |
4 | export interface RootStoreType extends Instance {}
5 |
6 | export const RootStore = RootStoreBase.actions((self) => ({
7 | // This is an auto-generated example action.
8 | log() {
9 | console.log(JSON.stringify(self))
10 | }
11 | }))
12 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/index.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | export * from "./PokemonModel"
6 | export * from "./PokemonDimensionModel"
7 | export * from "./PokemonAttackModel"
8 | export * from "./AttackModel"
9 | export * from "./PokemonEvolutionRequirementModel"
10 | export * from "./RootStore"
11 | export * from "./reactUtils"
12 |
--------------------------------------------------------------------------------
/examples/2-scaffolding/src/models/reactUtils.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { createStoreContext, createUseQueryHook } from "mst-gql"
6 | import * as React from "react"
7 | import { RootStoreType } from "./RootStore"
8 |
9 | export const StoreContext = createStoreContext(React)
10 |
11 | export const useQuery = createUseQueryHook(StoreContext, React)
12 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .build
3 | lib
4 | src/server/db/data.json
--------------------------------------------------------------------------------
/examples/3-twitter-clone/README.md:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | This example is a twttier clone that uses mst-gql.
4 |
5 | ## Usage
6 |
7 | #### 0. install `mst-gql` dependencies (within the parent `mst-gql` directory)
8 |
9 | ```bash
10 | yarn
11 | ```
12 |
13 | #### 1. Install dependencies (within this example's folder)
14 |
15 | ```bash
16 | yarn
17 | ```
18 |
19 | #### 2. Start server
20 |
21 | ```bash
22 | yarn start
23 | ```
24 |
25 | #### 3. Open browser
26 |
27 | Navigate to example at [http://localhost:3000/](http://localhost:3000/).
28 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | MST-GQL Twitter Clone Example
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/avatars/chuck.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/3-twitter-clone/src/app/avatars/chuck.jpg
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/avatars/michel.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/3-twitter-clone/src/app/avatars/michel.jpg
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/Composer.tsx:
--------------------------------------------------------------------------------
1 | import React, { useRef } from "react"
2 | import { observer } from "mobx-react-lite"
3 |
4 | import { MessageModelType } from "../models"
5 |
6 | import { Loading, Error } from "./utils"
7 | import { useQuery } from "../models/reactUtils"
8 |
9 | export const Composer = observer(
10 | ({ replyTo }: { replyTo?: MessageModelType }) => {
11 | const inputRef = useRef()
12 | const { store, loading, error, setQuery } = useQuery()
13 | return error ? (
14 | Failed to post message: ${error}
15 | ) : loading ? (
16 |
17 | ) : (
18 |
19 |
20 |
34 |
35 | )
36 | }
37 | )
38 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/Home.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { Composer } from "./Composer"
4 | import { MessageWall } from "./MessageWall"
5 |
6 | export const Home = () => (
7 | <>
8 |
9 | Share 🤯 experience...
10 |
11 |
12 |
13 |
14 |
15 | >
16 | )
17 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/Message.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { useState } from "react"
3 | import { observer } from "mobx-react-lite"
4 |
5 | import { MessageModelType } from "../models/"
6 | import { Replies } from "./Replies"
7 |
8 | // @ts-ignore
9 | import chuck from "../avatars/chuck.jpg"
10 | // @ts-ignore
11 | import michel from "../avatars/michel.jpg"
12 |
13 | const images = {
14 | michel,
15 | chuck
16 | }
17 |
18 | export const Message = observer(
19 | ({ message, asChild }: { message: MessageModelType; asChild?: boolean }) => {
20 | const [collapsed, setCollapsed] = useState(true)
21 | return (
22 |
23 |
24 |
25 |
{message.user.name}
26 |
{message.text}
27 |
28 |
32 | 💙
33 |
34 | {asChild ? null : (
35 |
setCollapsed((c) => !c)}>
36 | 💬
37 |
38 | )}
39 |
40 |
41 | {collapsed ? null : }
42 |
43 | )
44 | }
45 | )
46 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/MessageWall.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { observer } from "mobx-react-lite"
3 |
4 | import { Loading, Error } from "./utils"
5 |
6 | import { useQuery } from "../models/reactUtils"
7 | import { Message } from "./Message"
8 |
9 | export const MessageWall = observer(() => {
10 | const { store, error, loading, setQuery } = useQuery((store) =>
11 | store.loadInitialMessages()
12 | )
13 | if (error) return {error.message}
14 | if (!store.messages.size) return
15 | return (
16 | <>
17 |
18 | {store.sortedMessages.map((message) => (
19 |
20 | ))}
21 |
22 | {loading ? (
23 |
24 | ) : (
25 |
33 | )}
34 | >
35 | )
36 | })
37 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/Profile.tsx:
--------------------------------------------------------------------------------
1 | import React, { useRef } from "react"
2 | import { observer } from "mobx-react-lite"
3 |
4 | import { Error } from "./utils"
5 |
6 | import { useQuery } from "../models/reactUtils"
7 |
8 | export const Profile = observer(() => {
9 | const inputRef = useRef()
10 | const { loading, error, data, store, setQuery } = useQuery((store) =>
11 | store.queryMe()
12 | )
13 |
14 | if (error) return {error.message}
15 | return (
16 | <>
17 | Edit profile
18 |
23 |
31 | >
32 | )
33 | })
34 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/Replies.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { observer } from "mobx-react-lite"
3 |
4 | import { Loading, Error } from "./utils"
5 | import { Message } from "./Message"
6 | import { Composer } from "./Composer"
7 |
8 | import { useQuery } from "../models/reactUtils"
9 | import { MessageModelType } from "../models"
10 |
11 | export const Replies = observer(
12 | ({ message }: { message: MessageModelType }) => {
13 | const { data, error, loading } = useQuery(() => message.loadReplies())
14 | return (
15 |
16 | {error ? (
17 |
{error}
18 | ) : loading ? (
19 |
20 | ) : (
21 | <>
22 |
23 | {data.messages.map((message) => (
24 |
25 | ))}
26 |
27 |
28 | >
29 | )}
30 |
31 | )
32 | }
33 | )
34 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/utils/Error.tsx:
--------------------------------------------------------------------------------
1 | import React, { FC } from "react"
2 |
3 | export const Error: FC = (props) => (
4 | {props.children || "Something went wrong"}
5 | )
6 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/utils/Loading.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | export const Loading = () =>
4 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/utils/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./Error"
2 | export * from "./Loading"
3 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/components/utils/spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/3-twitter-clone/src/app/components/utils/spinner.gif
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import * as ReactDOM from "react-dom"
3 | import { createHttpClient } from "mst-gql"
4 | import { SubscriptionClient } from "subscriptions-transport-ws"
5 |
6 | import "./index.css"
7 |
8 | import { RootStore } from "./models/RootStore"
9 | import { StoreContext } from "./models/reactUtils"
10 |
11 | import { Home } from "./components/Home"
12 | import { Profile } from "./components/Profile"
13 |
14 | const gqlHttpClient = createHttpClient("http://localhost:4000/graphql")
15 |
16 | const gqlWsClient = new SubscriptionClient("ws://localhost:4000/graphql", {
17 | reconnect: true
18 | })
19 |
20 | const rootStore = RootStore.create(undefined, {
21 | gqlHttpClient,
22 | gqlWsClient
23 | })
24 |
25 | export const App = () => (
26 |
27 |
28 |
29 |
30 |
31 |
32 | )
33 |
34 | ReactDOM.render(, document.getElementById("root"))
35 |
36 | // For debugging
37 | // @ts-ignore
38 | window.store = rootStore
39 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/BaseIDModelSelector.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { QueryBuilder } from "mst-gql"
6 | import { MessageModelType } from "./MessageModel"
7 | import { MessageModelSelector } from "./MessageModel.base"
8 | import { UserModelType } from "./UserModel"
9 | import { UserModelSelector } from "./UserModel.base"
10 |
11 | export type BaseIDUnion = UserModelType | MessageModelType
12 |
13 | export class BaseIDModelSelector extends QueryBuilder {
14 | get id() { return this.__attr(`id`) }
15 | user(builder?: string | UserModelSelector | ((selector: UserModelSelector) => UserModelSelector)) { return this.__inlineFragment(`User`, UserModelSelector, builder) }
16 | message(builder?: string | MessageModelSelector | ((selector: MessageModelSelector) => MessageModelSelector)) { return this.__inlineFragment(`Message`, MessageModelSelector, builder) }
17 | }
18 | export function selectFromBaseID() {
19 | return new BaseIDModelSelector()
20 | }
21 |
22 | export const baseIDModelPrimitives = selectFromBaseID()
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/MessageModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { MessageModelBase } from "./MessageModel.base"
3 |
4 | /* The TypeScript type of an instance of MessageModel */
5 | export interface MessageModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for MessageModel */
8 | export {
9 | selectFromMessage,
10 | messageModelPrimitives,
11 | MessageModelSelector
12 | } from "./MessageModel.base"
13 |
14 | /**
15 | * MessageModel
16 | */
17 | export const MessageModel = MessageModelBase.views((self) => ({
18 | get isLikedByMe(): boolean {
19 | return self.likes.includes(self.store.me)
20 | }
21 | })).actions((self) => {
22 | let loadReplyQuery: ReturnType
23 |
24 | return {
25 | like() {
26 | return self.store.mutateLike(
27 | {
28 | msg: self.id,
29 | user: self.store.me.id
30 | },
31 | `__typename id likes { __typename id }`,
32 | () => {
33 | if (self.likes.includes(self.store.me))
34 | self.likes.remove(self.store.me)
35 | else self.likes.push(self.store.me)
36 | }
37 | )
38 | },
39 | loadReplies() {
40 | if (!loadReplyQuery) {
41 | loadReplyQuery = self.store.loadMessages("", 100, self.id)
42 | } else {
43 | loadReplyQuery.refetch()
44 | }
45 | return loadReplyQuery
46 | }
47 | }
48 | })
49 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/ModelBase.ts:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/SearchResultModelSelector.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { QueryBuilder } from "mst-gql"
6 | import { MessageModelType } from "./MessageModel"
7 | import { MessageModelSelector, messageModelPrimitives } from "./MessageModel.base"
8 | import { UserModelType } from "./UserModel"
9 | import { UserModelSelector, userModelPrimitives } from "./UserModel.base"
10 |
11 | export type SearchResultUnion = UserModelType | MessageModelType
12 |
13 | export class SearchResultModelSelector extends QueryBuilder {
14 | user(builder?: string | UserModelSelector | ((selector: UserModelSelector) => UserModelSelector)) { return this.__inlineFragment(`User`, UserModelSelector, builder) }
15 | message(builder?: string | MessageModelSelector | ((selector: MessageModelSelector) => MessageModelSelector)) { return this.__inlineFragment(`Message`, MessageModelSelector, builder) }
16 | }
17 | export function selectFromSearchResult() {
18 | return new SearchResultModelSelector()
19 | }
20 |
21 | // provides all primitive fields of union member types combined together
22 | export const searchResultModelPrimitives = selectFromSearchResult().user(userModelPrimitives).message(messageModelPrimitives)
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/UserModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * UserBase
13 | * auto generated base class for the model UserModel.
14 | */
15 | export const UserModelBase = ModelBase
16 | .named('User')
17 | .props({
18 | __typename: types.optional(types.literal("User"), "User"),
19 | id: types.identifier,
20 | name: types.union(types.undefined, types.string),
21 | avatar: types.union(types.undefined, types.string),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class UserModelSelector extends QueryBuilder {
30 | get id() { return this.__attr(`id`) }
31 | get name() { return this.__attr(`name`) }
32 | get avatar() { return this.__attr(`avatar`) }
33 | }
34 | export function selectFromUser() {
35 | return new UserModelSelector()
36 | }
37 |
38 | export const userModelPrimitives = selectFromUser().name.avatar
39 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/UserModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { UserModelBase } from "./UserModel.base"
3 |
4 | /* The TypeScript type of an instance of UserModel */
5 | export interface UserModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for UserModel */
8 | export {
9 | selectFromUser,
10 | userModelPrimitives,
11 | UserModelSelector
12 | } from "./UserModel.base"
13 |
14 | /**
15 | * UserModel
16 | */
17 | export const UserModel = UserModelBase.actions((self) => ({
18 | changeName(name: string) {
19 | return self.store.mutateChangeName(
20 | {
21 | id: self.id,
22 | name
23 | },
24 | (user) => user.name,
25 | () => {
26 | self.name = name
27 | }
28 | )
29 | }
30 | }))
31 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/index.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | export * from "./UserModel"
6 | export * from "./MessageModel"
7 | export * from "./SearchResultModelSelector"
8 | export * from "./RootStore"
9 | export * from "./reactUtils"
10 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/models/reactUtils.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { createStoreContext, createUseQueryHook } from "mst-gql"
6 | import * as React from "react"
7 | import { RootStoreType } from "./RootStore"
8 |
9 | export const StoreContext = createStoreContext(React)
10 |
11 | export const useQuery = createUseQueryHook(StoreContext, React)
12 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/app/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es6",
4 | "rootDir": "./",
5 | // "baseUrl": "./src/app",
6 | "strict": false,
7 | "lib": ["dom", "es2018", "esnext.asynciterable", "esnext.array"],
8 | "jsx": "react",
9 | "esModuleInterop": true,
10 | "moduleResolution": "node",
11 | "isolatedModules": true
12 | },
13 | "files": ["index.tsx"]
14 | }
15 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/index.ts:
--------------------------------------------------------------------------------
1 | import { ApolloServer } from "apollo-server-express"
2 | import cors from "cors"
3 | import express from "express"
4 | import http from "http"
5 |
6 | import { typeDefs, resolvers } from "./schema"
7 |
8 | const PORT = 4000
9 |
10 | const app = express()
11 | app.use(cors())
12 |
13 | const server = new ApolloServer({
14 | typeDefs,
15 | resolvers
16 | })
17 |
18 | server.applyMiddleware({ app })
19 |
20 | const httpServer = http.createServer(app)
21 | server.installSubscriptionHandlers(httpServer)
22 |
23 | httpServer.listen(PORT, () => {
24 | console.log(
25 | `🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`
26 | )
27 | console.log(
28 | `🚀 Subscriptions ready at ws://localhost:${PORT}${server.subscriptionsPath}`
29 | )
30 | })
31 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/MessageModel.ts:
--------------------------------------------------------------------------------
1 | import { MessageModelBase } from "./MessageModel.base"
2 | import { getSnapshot } from "mobx-state-tree"
3 |
4 | /* The TypeScript type of an instance of MessageModel */
5 | export type MessageModelType = typeof MessageModel.Type
6 |
7 | /**
8 | * MessageModel
9 | */
10 | export const MessageModel = MessageModelBase.views((self) => ({
11 | serialize() {
12 | return {
13 | ...getSnapshot(self),
14 | likes: self.likes.map((like) => like.serialize()),
15 | user: self.user.serialize()
16 | }
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/ModelBase.ts:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/ReplyModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { MSTGQLObject, MSTGQLRef } from "mst-gql"
7 |
8 | import { UserModel } from "./UserModel"
9 | import { RootStore } from "./index"
10 |
11 | /**
12 | * ReplyBase
13 | * auto generated base class for the model ReplyModel.
14 | */
15 | export const ReplyModelBase = MSTGQLObject
16 | .named('Reply')
17 | .props({
18 | __typename: types.optional(types.literal("Reply"), "Reply"),
19 | id: types.identifier,
20 | timestamp: types.number,
21 | user: MSTGQLRef(types.late(() => UserModel)),
22 | text: types.string,
23 | likes: types.array(MSTGQLRef(types.late(() => UserModel))),
24 | })
25 | .views(self => ({
26 | get store() {
27 | return self.__getStore()
28 | }
29 | }))
30 |
31 |
32 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/ReplyModel.ts:
--------------------------------------------------------------------------------
1 | import { ReplyModelBase } from "./ReplyModel.base"
2 | import { getSnapshot } from "mobx-state-tree"
3 |
4 | /* The TypeScript type of an instance of ReplyModel */
5 | export type ReplyModelType = typeof ReplyModel.Type
6 |
7 | /**
8 | * ReplyModel
9 | */
10 | export const ReplyModel = ReplyModelBase.views((self) => ({
11 | serialize() {
12 | return {
13 | ...getSnapshot(self),
14 | likes: self.likes.map((like) => like.serialize()),
15 | user: self.user.serialize()
16 | }
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/UserModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * UserBase
13 | * auto generated base class for the model UserModel.
14 | */
15 | export const UserModelBase = ModelBase
16 | .named('User')
17 | .props({
18 | __typename: types.optional(types.literal("User"), "User"),
19 | id: types.identifier,
20 | name: types.union(types.undefined, types.string),
21 | avatar: types.union(types.undefined, types.string),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 |
30 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/UserModel.ts:
--------------------------------------------------------------------------------
1 | import { UserModelBase } from "./UserModel.base"
2 | import { getSnapshot } from "mobx-state-tree"
3 |
4 | /* The TypeScript type of an instance of UserModel */
5 | export type UserModelType = typeof UserModel.Type
6 |
7 | /**
8 | * UserModel
9 | */
10 | export const UserModel = UserModelBase.actions((self) => ({
11 | setName(name: string) {
12 | self.name = name
13 | self.store.save()
14 | }
15 | })).views((self) => ({
16 | serialize() {
17 | return getSnapshot(self)
18 | }
19 | }))
20 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/index.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | export * from "./UserModel"
6 | export * from "./MessageModel"
7 | export * from "./RootStore"
8 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/models/reactUtils.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { createStoreContext, createUseQueryHook } from "mst-gql"
6 | import * as React from "react"
7 | import { RootStore } from "./RootStore"
8 |
9 | export const StoreContext = createStoreContext(React)
10 |
11 | export const useQuery = createUseQueryHook(StoreContext, React)
12 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/schema.graphql:
--------------------------------------------------------------------------------
1 | type User {
2 | id: ID
3 | name: String!
4 | avatar: String!
5 | }
6 | type Message {
7 | id: ID
8 | timestamp: Float!
9 | user: User!
10 | text: String!
11 | likes: [User!]
12 | replyTo: Message
13 | }
14 | type Query {
15 | search(searchText: String!): [SearchResult!]
16 | messages(offset: ID, count: Int, replyTo: ID): [Message]
17 | message(id: ID!): Message
18 | me: User
19 | }
20 | type Subscription {
21 | newMessages: Message
22 | }
23 | type Mutation {
24 | changeName(id: ID!, name: String!): User
25 | like(msg: ID!, user: ID!): Message
26 | postTweet(text: String!, user: ID!, replyTo: ID): Message
27 | }
28 |
29 | union SearchResult = User | Message
30 |
--------------------------------------------------------------------------------
/examples/3-twitter-clone/src/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "rootDir": "./src/server",
5 | "baseUrl": "./src/server",
6 | "strict": false,
7 | "lib": ["es2018", "esnext.asynciterable", "esnext.array"],
8 | "jsx": "react",
9 | "esModuleInterop": true,
10 | "moduleResolution": "node",
11 | "isolatedModules": true
12 | },
13 | "files": ["index.ts"]
14 | }
15 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/README.md:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | Based on the [apollo full-stack tutorial](https://github.com/apollographql/fullstack-tutorial/tree/d780ec0ceed274fdc296eebfaf20d54499e8ea31/final)
4 |
5 | ## Usage
6 |
7 | #### 0. install `mst-gql` dependencies (within the parent `mst-gql` directory)
8 |
9 | ```bash
10 | yarn
11 | ```
12 |
13 | #### 1. Add `ENGINE_API_KEY`
14 |
15 | 1. Visit (https://engine.apollographql.com/)[Apollo] and create an account.
16 | 2. Create a new graph
17 | 3. grab the `ENGINE_API_KEY` they give you and add it to a `.env` file within the `server` in this example.
18 |
19 | #### 2. Run the server
20 |
21 | ```bash
22 | cd server
23 | yarn
24 | yarn start
25 | ```
26 |
27 | #### 3. Run the client (in another terminal)
28 |
29 | ```bash
30 | cd client
31 | yarn
32 | yarn start
33 | ```
34 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/.env:
--------------------------------------------------------------------------------
1 | SKIP_PREFLIGHT_CHECK=true
2 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/.env.example:
--------------------------------------------------------------------------------
1 | ENGINE_API_KEY=
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/README.md:
--------------------------------------------------------------------------------
1 | # Apollo Fullstack Tutorial
2 |
3 | ## Client
4 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/apollo.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | client: {
3 | name: "Space Explorer [web]",
4 | service: "space-explorer"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "0.1.0",
4 | "scripts": {
5 | "build": "react-scripts build",
6 | "eject": "react-scripts eject",
7 | "scaffold": "node ../../../generator/mst-gql-scaffold.js --excludes TripUpdateResponse --format js demo_schema.json",
8 | "start": "yarn scaffold && wait-port 4000 && react-scripts start",
9 | "test": "react-scripts test"
10 | },
11 | "dependencies": {
12 | "@reach/router": "^1.2.1",
13 | "emotion": "^10.0.6",
14 | "mst-gql": "portal:../../../",
15 | "polished": "^2.3.3",
16 | "react": "^18.2.0",
17 | "react-dom": "^18.2.0",
18 | "react-emotion": "^9.2.12",
19 | "react-scripts": "^5.0.1"
20 | },
21 | "devDependencies": {
22 | "graphql": "^16.8.1",
23 | "graphql-request": "^6.1.0",
24 | "jest-dom": "^3.0.0",
25 | "mobx": "^6.10.2",
26 | "mobx-react": "^7.5.0",
27 | "mobx-state-tree": "^5.3.0",
28 | "react-testing-library": "^5.4.4",
29 | "wait-port": "^0.2.9"
30 | },
31 | "browserslist": [
32 | ">0.2%",
33 | "not dead",
34 | "not ie <= 11",
35 | "not op_mini all"
36 | ],
37 | "eslintConfig": {
38 | "extends": "react-app"
39 | },
40 | "private": true
41 | }
42 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/public/favicon.ico
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "Launches",
3 | "name": "Launches",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/curve.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/badge-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/badge-1.png
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/badge-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/badge-2.png
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/badge-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/badge-3.png
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/dog-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/dog-1.png
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/dog-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/dog-2.png
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/dog-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/dog-3.png
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/galaxy.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/galaxy.jpg
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/iss.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/iss.jpg
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/moon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/moon.jpg
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/assets/images/space.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/client/src/assets/images/space.jpg
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/button.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import Button from "../button"
5 |
6 | describe("Button", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/footer.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { renderApollo, cleanup } from "../../test-utils"
4 | import Footer from "../footer"
5 |
6 | describe("Footer", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | renderApollo()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/header.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import Header from "../header"
5 |
6 | describe("Header", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/launch-detail.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import LaunchDetail from "../launch-detail"
5 |
6 | describe("Launch Detail View", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render(
12 |
17 | )
18 | })
19 | })
20 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/launch-tile.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import LaunchTile from "../launch-tile"
5 |
6 | describe("Launch Tile", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render(
12 |
19 | )
20 | })
21 | })
22 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/loading.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import Loading from "../loading"
5 |
6 | describe("Loading", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/login-form.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import LoginForm from "../login-form"
5 |
6 | describe("Login Form", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/menu-item.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import MenuItem from "../menu-item"
5 |
6 | describe("Menu Item", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/__tests__/page-container.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { render, cleanup } from "../../test-utils"
4 | import PageContainer from "../page-container"
5 |
6 | describe("Page Container", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders without error", () => {
11 | render()
12 | })
13 | })
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/button.js:
--------------------------------------------------------------------------------
1 | import styled from "react-emotion"
2 | import { lighten } from "polished"
3 |
4 | import { unit, colors } from "../styles"
5 |
6 | const height = 50
7 | export default styled("button")({
8 | display: "block",
9 | minWidth: 200,
10 | height,
11 | margin: "0 auto",
12 | padding: `0 ${unit * 4}px`,
13 | border: "none",
14 | borderRadius: height / 2,
15 | fontFamily: "inherit",
16 | fontSize: 18,
17 | lineHeight: `${height}px`,
18 | fontWeight: 700,
19 | color: "white",
20 | textTransform: "uppercase",
21 | backgroundColor: colors.accent,
22 | cursor: "pointer",
23 | outline: "none",
24 | ":hover": {
25 | backgroundColor: lighten(0.1, colors.accent)
26 | },
27 | ":active": {
28 | backgroundColor: lighten(0.2, colors.accent)
29 | }
30 | })
31 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/footer.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import styled from "react-emotion"
3 |
4 | import MenuItem from "./menu-item"
5 | import LogoutButton from "../containers/logout-button"
6 | import { ReactComponent as HomeIcon } from "../assets/icons/home.svg"
7 | import { ReactComponent as CartIcon } from "../assets/icons/cart.svg"
8 | import { ReactComponent as ProfileIcon } from "../assets/icons/profile.svg"
9 | import { colors, unit } from "../styles"
10 |
11 | export default function Footer() {
12 | return (
13 |
14 |
15 |
19 |
23 |
27 |
28 |
29 |
30 | )
31 | }
32 |
33 | /**
34 | * STYLED COMPONENTS USED IN THIS FILE ARE BELOW HERE
35 | */
36 |
37 | const Container = styled("footer")({
38 | flexShrink: 0,
39 | marginTop: "auto",
40 | backgroundColor: "white",
41 | color: colors.textSecondary,
42 | position: "sticky",
43 | bottom: 0
44 | })
45 |
46 | const InnerContainer = styled("div")({
47 | display: "flex",
48 | alignItems: "center",
49 | maxWidth: 460,
50 | padding: unit * 2.5,
51 | margin: "0 auto"
52 | })
53 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/index.js:
--------------------------------------------------------------------------------
1 | export { default as Button } from "./button"
2 | export { default as Footer } from "./footer"
3 | export { default as Header } from "./header"
4 | export { default as LaunchDetail } from "./launch-detail"
5 | export { default as LaunchTile } from "./launch-tile"
6 | export { default as Loading } from "./loading"
7 | export { default as LoginForm } from "./login-form"
8 | export { default as MenuItem } from "./menu-item"
9 | export { default as PageContainer } from "./page-container"
10 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/launch-detail.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import styled from "react-emotion"
3 |
4 | import { unit } from "../styles"
5 | import { cardClassName, getBackgroundImage } from "./launch-tile"
6 |
7 | const LaunchDetail = ({ id, site, rocket }) => (
8 |
13 |
14 | {rocket.name} ({rocket.type})
15 |
16 | {site}
17 |
18 | )
19 |
20 | /**
21 | * STYLED COMPONENTS USED IN THIS FILE ARE BELOW HERE
22 | */
23 |
24 | const Card = styled("div")(cardClassName, {
25 | height: 365,
26 | marginBottom: unit * 4
27 | })
28 |
29 | export default LaunchDetail
30 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/launch-tile.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import styled, { css } from "react-emotion"
3 | import { Link } from "@reach/router"
4 |
5 | import galaxy from "../assets/images/galaxy.jpg"
6 | import iss from "../assets/images/iss.jpg"
7 | import moon from "../assets/images/moon.jpg"
8 | import { unit } from "../styles"
9 |
10 | const backgrounds = [galaxy, iss, moon]
11 | export function getBackgroundImage(id) {
12 | return `url(${backgrounds[Number(id) % backgrounds.length]})`
13 | }
14 |
15 | export default ({ launch }) => {
16 | const { id, mission, rocket } = launch
17 | return (
18 |
24 | {mission.name}
25 | {rocket.name}
26 |
27 | )
28 | }
29 |
30 | /**
31 | * STYLED COMPONENTS USED IN THIS FILE ARE BELOW HERE
32 | */
33 |
34 | export const cardClassName = css({
35 | padding: `${unit * 4}px ${unit * 5}px`,
36 | borderRadius: 7,
37 | color: "white",
38 | backgroundSize: "cover",
39 | backgroundPosition: "center"
40 | })
41 |
42 | const padding = unit * 2
43 | const StyledLink = styled(Link)(cardClassName, {
44 | display: "block",
45 | height: 193,
46 | marginTop: padding,
47 | textDecoration: "none",
48 | ":not(:last-child)": {
49 | marginBottom: padding * 2
50 | }
51 | })
52 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/loading.js:
--------------------------------------------------------------------------------
1 | import styled, { keyframes } from "react-emotion"
2 | import { size } from "polished"
3 |
4 | import { ReactComponent as Logo } from "../assets/logo.svg"
5 | import { colors } from "../styles"
6 |
7 | const spin = keyframes`
8 | to {
9 | transform: rotate(360deg);
10 | }
11 | `
12 |
13 | const Loading = styled(Logo)(size(64), {
14 | display: "block",
15 | margin: "auto",
16 | fill: colors.grey,
17 | path: {
18 | transformOrigin: "center",
19 | animation: `${spin} 1s linear infinite`
20 | }
21 | })
22 |
23 | export default Loading
24 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/menu-item.js:
--------------------------------------------------------------------------------
1 | import styled, { css } from "react-emotion"
2 | import { Link } from "@reach/router"
3 | import { colors, unit } from "../styles"
4 |
5 | export const menuItemClassName = css({
6 | flexGrow: 1,
7 | width: 0,
8 | fontFamily: "inherit",
9 | fontSize: 20,
10 | color: "inherit",
11 | letterSpacing: 1.5,
12 | textTransform: "uppercase",
13 | textAlign: "center",
14 | svg: {
15 | display: "block",
16 | width: 60,
17 | margin: `0 auto ${unit}px`,
18 | fill: colors.secondary
19 | }
20 | })
21 |
22 | const MenuItem = styled(Link)(menuItemClassName, {
23 | textDecoration: "none"
24 | })
25 |
26 | export default MenuItem
27 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/components/page-container.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react"
2 | import styled from "react-emotion"
3 |
4 | import { unit, colors } from "../styles"
5 |
6 | export default function PageContainer(props) {
7 | return (
8 |
9 |
10 | {props.children}
11 |
12 | )
13 | }
14 |
15 | /**
16 | * STYLED COMPONENTS USED IN THIS FILE ARE BELOW HERE
17 | */
18 |
19 | const Bar = styled("div")({
20 | flexShrink: 0,
21 | height: 12,
22 | backgroundColor: colors.primary
23 | })
24 |
25 | const Container = styled("div")({
26 | display: "flex",
27 | flexDirection: "column",
28 | flexGrow: 1,
29 | width: "100%",
30 | maxWidth: 600,
31 | margin: "0 auto",
32 | padding: unit * 3,
33 | paddingBottom: unit * 5
34 | })
35 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/containers/__tests__/logout-button.js:
--------------------------------------------------------------------------------
1 | // TODO
2 | it("", () => {})
3 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/containers/action-button.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { observer } from "mobx-react"
3 | import Button from "../components/button"
4 | import { useQuery } from "../models/reactUtils"
5 |
6 | export default observer(function ActionButton({ launch }) {
7 | const { store, setQuery, loading, error } = useQuery()
8 |
9 | if (loading) return Loading...
10 | if (error) return An error occurred
11 |
12 | return (
13 |
14 |
29 |
30 | )
31 | })
32 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/containers/book-trips.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { observer } from "mobx-react"
3 |
4 | import Button from "../components/button"
5 | import { GET_LAUNCH } from "./cart-item"
6 | import { useQuery } from "../models/reactUtils"
7 |
8 | export { GET_LAUNCH }
9 |
10 | export default observer(function BookTrips() {
11 | const { store, setQuery, data } = useQuery()
12 |
13 | if (data && data.bookTrips && !data.bookTrips.success)
14 | return {data.bookTrips.message}
15 | return (
16 |
22 | )
23 | })
24 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/containers/cart-item.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import gql from "graphql-tag"
3 | import { observer } from "mobx-react"
4 |
5 | import LaunchTile from "../components/launch-tile"
6 |
7 | import { useQuery } from "../models/reactUtils"
8 | import { LAUNCH_TILE_DATA } from "../models/"
9 |
10 | export const GET_LAUNCH = gql`
11 | query GetLaunch($launchId: ID!) {
12 | launch(id: $launchId) {
13 | ...LaunchTile
14 | }
15 | }
16 | ${LAUNCH_TILE_DATA}
17 | `
18 |
19 | export default observer(function CartItem({ launchId }) {
20 | const { query } = useQuery(GET_LAUNCH, { variables: { launchId } })
21 | return query.case({
22 | error: (error) => ERROR: {error.message}
,
23 | loading: () => Loading...
,
24 | data: ({ launch }) =>
25 | })
26 | })
27 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/containers/index.js:
--------------------------------------------------------------------------------
1 | export { default as ActionButton } from "./action-button"
2 | export { default as BookTrips } from "./book-trips"
3 | export { default as CartItem } from "./cart-item"
4 | export { default as LogoutButton } from "./logout-button"
5 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/containers/logout-button.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from "react"
2 | import styled from "react-emotion"
3 |
4 | import { menuItemClassName } from "../components/menu-item"
5 | import { ReactComponent as ExitIcon } from "../assets/icons/exit.svg"
6 | import { StoreContext } from "../models"
7 |
8 | export default function LogoutButton() {
9 | const store = useContext(StoreContext)
10 | return (
11 |
12 |
13 | Logout
14 |
15 | )
16 | }
17 |
18 | /**
19 | * STYLED COMPONENTS USED IN THIS FILE ARE BELOW HERE
20 | */
21 |
22 | const StyledButton = styled("button")(menuItemClassName, {
23 | background: "none",
24 | border: "none",
25 | padding: 0
26 | })
27 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/LaunchConnectionModel.js:
--------------------------------------------------------------------------------
1 | import { LaunchConnectionModelBase } from "./LaunchConnectionModel.base"
2 |
3 | /* A graphql query fragment builders for LaunchConnectionModel */
4 | export {
5 | selectFromLaunchConnection,
6 | launchConnectionModelPrimitives,
7 | LaunchConnectionModelSelector
8 | } from "./LaunchConnectionModel.base"
9 |
10 | /**
11 | * LaunchConnectionModel
12 | *
13 | * Simple wrapper around our list of launches that contains a cursor to the last item in the list. Pass this cursor to the launches query to fetch results after these.
14 | */
15 | export const LaunchConnectionModel = LaunchConnectionModelBase.volatile(
16 | (self) => ({
17 | isFetchingMore: false
18 | })
19 | ).actions((self) => ({
20 | fetchMore() {
21 | self.isFetchingMore = true
22 | const query = self.store.fetchLaunches(self.cursor)
23 | query.then((lc) => self.doneFetchingMore(lc))
24 | return query
25 | },
26 | doneFetchingMore(launchConnection) {
27 | self.isFetchingMore = false
28 | self.cursor = launchConnection.cursor
29 | self.hasMore = launchConnection.hasMore
30 | self.launches.push(...launchConnection.launches)
31 | }
32 | }))
33 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/LaunchModel.js:
--------------------------------------------------------------------------------
1 | import { LaunchModelBase } from "./LaunchModel.base"
2 |
3 | /* A graphql query fragment builders for LaunchModel */
4 | export {
5 | selectFromLaunch,
6 | launchModelPrimitives,
7 | LaunchModelSelector
8 | } from "./LaunchModel.base"
9 |
10 | /**
11 | * LaunchModel
12 | */
13 | export const LaunchModel = LaunchModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | })).views((self) => ({
19 | get isInCart() {
20 | return self.store.cartItems.includes(self.id)
21 | }
22 | }))
23 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/MissionModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 | import { PatchSize } from "./PatchSizeEnum"
8 |
9 |
10 | /**
11 | * MissionBase
12 | * auto generated base class for the model MissionModel.
13 | */
14 | export const MissionModelBase = ModelBase
15 | .named('Mission')
16 | .props({
17 | __typename: types.optional(types.literal("Mission"), "Mission"),
18 | name: types.union(types.undefined, types.null, types.string),
19 | missionPatch: types.union(types.undefined, types.null, types.string),
20 | })
21 | .views(self => ({
22 | get store() {
23 | return self.__getStore()
24 | }
25 | }))
26 |
27 | export class MissionModelSelector extends QueryBuilder {
28 | get name() { return this.__attr(`name`) }
29 | get missionPatch() { return this.__attr(`missionPatch`) }
30 | }
31 | export function selectFromMission() {
32 | return new MissionModelSelector()
33 | }
34 |
35 | export const missionModelPrimitives = selectFromMission().name.missionPatch
36 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/MissionModel.js:
--------------------------------------------------------------------------------
1 | import { MissionModelBase } from "./MissionModel.base"
2 |
3 | /* A graphql query fragment builders for MissionModel */
4 | export {
5 | selectFromMission,
6 | missionModelPrimitives,
7 | MissionModelSelector
8 | } from "./MissionModel.base"
9 |
10 | /**
11 | * MissionModel
12 | */
13 | export const MissionModel = MissionModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/ModelBase.js:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/PatchSizeEnum.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | import { types } from "mobx-state-tree"
4 |
5 |
6 |
7 | /**
8 | * PatchSize
9 | */
10 | export const PatchSizeEnumType = types.enumeration("PatchSize", [
11 | "SMALL",
12 | "LARGE",
13 | ])
14 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/RocketModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * RocketBase
11 | * auto generated base class for the model RocketModel.
12 | */
13 | export const RocketModelBase = ModelBase
14 | .named('Rocket')
15 | .props({
16 | __typename: types.optional(types.literal("Rocket"), "Rocket"),
17 | id: types.identifier,
18 | name: types.union(types.undefined, types.null, types.string),
19 | type: types.union(types.undefined, types.null, types.string),
20 | })
21 | .views(self => ({
22 | get store() {
23 | return self.__getStore()
24 | }
25 | }))
26 |
27 | export class RocketModelSelector extends QueryBuilder {
28 | get id() { return this.__attr(`id`) }
29 | get name() { return this.__attr(`name`) }
30 | get type() { return this.__attr(`type`) }
31 | }
32 | export function selectFromRocket() {
33 | return new RocketModelSelector()
34 | }
35 |
36 | export const rocketModelPrimitives = selectFromRocket().name.type
37 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/RocketModel.js:
--------------------------------------------------------------------------------
1 | import { RocketModelBase } from "./RocketModel.base"
2 |
3 | /* A graphql query fragment builders for RocketModel */
4 | export {
5 | selectFromRocket,
6 | rocketModelPrimitives,
7 | RocketModelSelector
8 | } from "./RocketModel.base"
9 |
10 | /**
11 | * RocketModel
12 | */
13 | export const RocketModel = RocketModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/UserModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { MSTGQLRef, QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 | import { LaunchModel } from "./LaunchModel"
8 | import { LaunchModelSelector } from "./LaunchModel.base"
9 |
10 |
11 | /**
12 | * UserBase
13 | * auto generated base class for the model UserModel.
14 | */
15 | export const UserModelBase = ModelBase
16 | .named('User')
17 | .props({
18 | __typename: types.optional(types.literal("User"), "User"),
19 | id: types.identifier,
20 | email: types.union(types.undefined, types.string),
21 | trips: types.union(types.undefined, types.array(types.union(types.null, MSTGQLRef(types.late(() => LaunchModel))))),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class UserModelSelector extends QueryBuilder {
30 | get id() { return this.__attr(`id`) }
31 | get email() { return this.__attr(`email`) }
32 | trips(builder) { return this.__child(`trips`, LaunchModelSelector, builder) }
33 | }
34 | export function selectFromUser() {
35 | return new UserModelSelector()
36 | }
37 |
38 | export const userModelPrimitives = selectFromUser().email
39 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/UserModel.js:
--------------------------------------------------------------------------------
1 | import { UserModelBase } from "./UserModel.base"
2 |
3 | /* A graphql query fragment builders for UserModel */
4 | export {
5 | selectFromUser,
6 | userModelPrimitives,
7 | UserModelSelector
8 | } from "./UserModel.base"
9 |
10 | /**
11 | * UserModel
12 | */
13 | export const UserModel = UserModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/index.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | export * from "./LaunchConnectionModel"
5 | export * from "./LaunchModel"
6 | export * from "./MissionModel"
7 | export * from "./PatchSizeEnum"
8 | export * from "./RocketModel"
9 | export * from "./UserModel"
10 | export * from "./RootStore"
11 | export * from "./reactUtils"
12 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/models/reactUtils.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { createStoreContext, createUseQueryHook } from "mst-gql"
5 | import * as React from "react"
6 |
7 |
8 | export const StoreContext = createStoreContext(React)
9 |
10 | export const useQuery = createUseQueryHook(StoreContext, React)
11 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/__tests__/cart.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { renderApollo, cleanup, waitForElement } from "../../test-utils"
4 | import Cart, { GET_CART_ITEMS } from "../cart"
5 |
6 | describe("Cart Page", () => {
7 | // automatically unmount and cleanup DOM after the test is finished.
8 | afterEach(cleanup)
9 |
10 | it("renders with message for empty carts", () => {
11 | let mocks = [
12 | {
13 | request: { query: GET_CART_ITEMS },
14 | result: { data: { cartItems: [] } }
15 | }
16 | ]
17 | const { getByTestId } = renderApollo(, { mocks })
18 | return waitForElement(() => getByTestId("empty-message"))
19 | })
20 |
21 | it("renders cart", () => {
22 | let mocks = [
23 | {
24 | request: { query: GET_CART_ITEMS },
25 | result: { data: { cartItems: [1] } }
26 | }
27 | ]
28 | const { getByTestId } = renderApollo(, { mocks })
29 | return waitForElement(() => getByTestId("empty-message"))
30 | })
31 | })
32 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/__tests__/launch.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { renderApollo, cleanup, waitForElement } from "../../test-utils"
4 | import Launch, { GET_LAUNCH_DETAILS } from "../launch"
5 |
6 | const mockLaunch = {
7 | __typename: "Launch",
8 | id: 1,
9 | isBooked: true,
10 | rocket: {
11 | __typename: "Rocket",
12 | id: 1,
13 | name: "tester",
14 | type: "test"
15 | },
16 | mission: {
17 | __typename: "Mission",
18 | id: 1,
19 | name: "test mission",
20 | missionPatch: "/"
21 | },
22 | site: "earth",
23 | isInCart: false
24 | }
25 |
26 | describe("Launch Page", () => {
27 | // automatically unmount and cleanup DOM after the test is finished.
28 | afterEach(cleanup)
29 |
30 | it("renders launch", async () => {
31 | const mocks = [
32 | {
33 | request: { query: GET_LAUNCH_DETAILS, variables: { launchId: 1 } },
34 | result: { data: { launch: mockLaunch } }
35 | }
36 | ]
37 | const { getByText } = await renderApollo(, {
38 | mocks
39 | })
40 | await waitForElement(() => getByText(/test mission/i))
41 | })
42 | })
43 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/__tests__/launches.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { InMemoryCache } from "apollo-cache-inmemory"
3 |
4 | import { renderApollo, cleanup, waitForElement } from "../../test-utils"
5 | import Launches, { GET_LAUNCHES } from "../launches"
6 |
7 | const mockLaunch = {
8 | __typename: "Launch",
9 | id: 1,
10 | isBooked: true,
11 | rocket: {
12 | __typename: "Rocket",
13 | id: 1,
14 | name: "tester",
15 | type: "test"
16 | },
17 | mission: {
18 | __typename: "Mission",
19 | id: 1,
20 | name: "test mission",
21 | missionPatch: "/"
22 | },
23 | site: "earth",
24 | isInCart: false
25 | }
26 |
27 | describe("Launches Page", () => {
28 | // automatically unmount and cleanup DOM after the test is finished.
29 | afterEach(cleanup)
30 |
31 | it("renders launches", async () => {
32 | const cache = new InMemoryCache({ addTypename: false })
33 | const mocks = [
34 | {
35 | request: { query: GET_LAUNCHES },
36 | result: {
37 | data: {
38 | launches: {
39 | cursor: "123",
40 | hasMore: true,
41 | launches: [mockLaunch]
42 | }
43 | }
44 | }
45 | }
46 | ]
47 | const { getByText } = await renderApollo(, {
48 | mocks,
49 | cache
50 | })
51 | await waitForElement(() => getByText(/test mission/i))
52 | })
53 | })
54 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/__tests__/profile.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 |
3 | import { renderApollo, cleanup, waitForElement } from "../../test-utils"
4 | import Profile, { GET_MY_TRIPS } from "../profile"
5 |
6 | const mockLaunch = {
7 | __typename: "Launch",
8 | id: 1,
9 | isBooked: true,
10 | rocket: {
11 | __typename: "Rocket",
12 | id: 1,
13 | name: "tester"
14 | },
15 | mission: {
16 | __typename: "Mission",
17 | id: 1,
18 | name: "test mission",
19 | missionPatch: "/"
20 | }
21 | }
22 |
23 | const mockMe = {
24 | __typename: "User",
25 | id: 1,
26 | email: "a@a.a",
27 | trips: [mockLaunch]
28 | }
29 |
30 | describe("Profile Page", () => {
31 | // automatically unmount and cleanup DOM after the test is finished.
32 | afterEach(cleanup)
33 |
34 | it("renders profile page", async () => {
35 | const mocks = [
36 | {
37 | request: { query: GET_MY_TRIPS },
38 | result: { data: { me: mockMe } }
39 | }
40 | ]
41 |
42 | const { getByText } = renderApollo(, { mocks })
43 |
44 | // if the profile renders, it will have the list of missions booked
45 | await waitForElement(() => getByText(/test mission/i))
46 | })
47 | })
48 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/cart.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment, useContext } from "react"
2 | import { observer } from "mobx-react"
3 |
4 | import { StoreContext } from "../models/reactUtils"
5 | import { Header } from "../components"
6 | import { CartItem, BookTrips } from "../containers"
7 |
8 | export default observer(function Cart() {
9 | const store = useContext(StoreContext)
10 | return (
11 |
12 |
13 | {!store.cartItems.length ? (
14 | No items in your cart
15 | ) : (
16 |
17 | {store.cartItems.map((launchId) => (
18 |
19 | ))}
20 |
21 |
22 | )}
23 |
24 | )
25 | })
26 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/index.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react"
2 | import { Router } from "@reach/router"
3 |
4 | import Launch from "./launch"
5 | import Launches from "./launches"
6 | import Cart from "./cart"
7 | import Profile from "./profile"
8 | import { Footer, PageContainer } from "../components"
9 |
10 | export default function Pages() {
11 | return (
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | )
24 | }
25 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/launch.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react"
2 | import gql from "graphql-tag"
3 | import { observer } from "mobx-react"
4 |
5 | import { useQuery } from "../models/reactUtils"
6 | import { LAUNCH_TILE_DATA } from "../models/"
7 | import { Loading, Header, LaunchDetail } from "../components"
8 | import { ActionButton } from "../containers"
9 |
10 | export const GET_LAUNCH_DETAILS = gql`
11 | query LaunchDetails($launchId: ID!) {
12 | launch(id: $launchId) {
13 | site
14 | rocket {
15 | type
16 | }
17 | ...LaunchTile
18 | }
19 | }
20 | ${LAUNCH_TILE_DATA}
21 | `
22 |
23 | export default observer(function Launch({ launchId }) {
24 | const { query } = useQuery(GET_LAUNCH_DETAILS, { variables: { launchId } })
25 | return query.case({
26 | error: (error) => ERROR: {error.message}
,
27 | loading: () => ,
28 | data: ({ launch }) => (
29 |
30 |
31 | {launch.mission.name}
32 |
33 |
34 |
35 |
36 | )
37 | })
38 | })
39 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/launches.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react"
2 | import { observer } from "mobx-react"
3 |
4 | import { LaunchTile, Header, Button, Loading } from "../components"
5 | import { useQuery } from "../models/reactUtils"
6 |
7 | export default observer(function Launches() {
8 | const { query } = useQuery((store) => store.fetchLaunches())
9 | return (
10 |
11 |
12 | {query.case({
13 | error: () => ERROR
,
14 | loading: () => ,
15 | data: ({ launches: launchConnection }) => (
16 |
17 | {launchConnection.launches.map((launch) => (
18 |
19 | ))}
20 | {launchConnection.isFetchingMore ? (
21 |
22 | ) : launchConnection.hasMore ? (
23 |
30 | ) : null}
31 |
32 | )
33 | })}
34 |
35 | )
36 | })
37 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/login.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from "react"
2 |
3 | import { StoreContext } from "../models"
4 | import { LoginForm, Loading } from "../components"
5 |
6 | export default function Login() {
7 | const store = useContext(StoreContext)
8 | switch (store.loginStatus) {
9 | case "loggedIn":
10 | case "pending":
11 | return
12 | case "loggedOut":
13 | return store.login(email)} />
14 | default:
15 | return An error occurred
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/pages/profile.js:
--------------------------------------------------------------------------------
1 | import React, { Fragment } from "react"
2 |
3 | import { LAUNCH_TILE_DATA, useQuery } from "../models"
4 | import { Loading, Header, LaunchTile } from "../components"
5 | import { observer } from "mobx-react"
6 | import gql from "graphql-tag"
7 |
8 | export const GET_MY_TRIPS = gql`
9 | query GetMyTrips {
10 | me {
11 | id
12 | __typename
13 | email
14 | trips {
15 | ...LaunchTile
16 | }
17 | }
18 | }
19 | ${LAUNCH_TILE_DATA}
20 | `
21 |
22 | export default observer(function Profile() {
23 | const { query, store } = useQuery(GET_MY_TRIPS)
24 |
25 | return query.case({
26 | error: (error) => ERROR: {error.message}
,
27 | // render cached trips if available
28 | loading: () => (store.hasTrips ? renderTrips(store) : ),
29 | data: () => renderTrips(store)
30 | })
31 | })
32 |
33 | function renderTrips(store) {
34 | return (
35 |
36 |
37 | {store.hasTrips ? (
38 | store.me.trips.map((launch) => (
39 |
40 | ))
41 | ) : (
42 | You haven't booked any trips
43 | )}
44 |
45 | )
46 | }
47 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/styles.js:
--------------------------------------------------------------------------------
1 | import { injectGlobal } from "react-emotion"
2 |
3 | export const unit = 8
4 | export const colors = {
5 | primary: "#220a82",
6 | secondary: "#14cbc4",
7 | accent: "#e535ab",
8 | background: "#f7f8fa",
9 | grey: "#d8d9e0",
10 | text: "#343c5a",
11 | textSecondary: "#747790"
12 | }
13 |
14 | export default () =>
15 | injectGlobal({
16 | [["html", "body"]]: {
17 | height: "100%"
18 | },
19 | body: {
20 | margin: 0,
21 | padding: 0,
22 | fontFamily: "'Source Sans Pro', sans-serif",
23 | backgroundColor: colors.background,
24 | color: colors.text
25 | },
26 | "#root": {
27 | display: "flex",
28 | flexDirection: "column",
29 | minHeight: "100%"
30 | },
31 | "*": {
32 | boxSizing: "border-box"
33 | },
34 | [["h1", "h2", "h3", "h4", "h5", "h6"]]: {
35 | margin: 0,
36 | fontWeight: 600
37 | },
38 | h1: {
39 | fontSize: 48,
40 | lineHeight: 1
41 | },
42 | h2: {
43 | fontSize: 40
44 | },
45 | h3: {
46 | fontSize: 36
47 | },
48 | h5: {
49 | fontSize: 16,
50 | textTransform: "uppercase",
51 | letterSpacing: 4
52 | }
53 | })
54 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/client/src/test-utils.js:
--------------------------------------------------------------------------------
1 | import React from "react"
2 | import { render } from "react-testing-library"
3 | // this adds custom jest matchers from jest-dom
4 | import "jest-dom/extend-expect"
5 | import { MockedProvider } from "react-apollo/test-utils"
6 |
7 | const renderApollo = (
8 | node,
9 | { mocks, addTypename, defaultOptions, cache, ...options } = {}
10 | ) => {
11 | return render(
12 |
18 | {node}
19 | ,
20 | options
21 | )
22 | }
23 |
24 | export * from "react-testing-library"
25 | export { renderApollo }
26 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/.env.example:
--------------------------------------------------------------------------------
1 | ENGINE_API_KEY=
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/apollo.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | service: {
3 | name: "space-explorer"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/now.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "builds": [{ "src": "src/index.js", "use": "@now/node-server" }],
4 | "routes": [{ "src": "/.*", "dest": "src/index.js" }]
5 | }
6 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fullstack-tutorial-server",
3 | "description": "",
4 | "license": "ISC",
5 | "version": "1.0.0",
6 | "author": "",
7 | "scripts": {
8 | "start": "nodemon src/index.js",
9 | "start:ci": "node src/index.js",
10 | "test": "jest"
11 | },
12 | "dependencies": {
13 | "apollo-datasource": "^0.1.3",
14 | "apollo-datasource-rest": "^0.1.5",
15 | "apollo-server": "^2.9.4",
16 | "apollo-server-testing": "^2.9.4",
17 | "dotenv": "^6.1.0",
18 | "graphql": "15.8.0",
19 | "isemail": "^3.1.3",
20 | "nodemon": "^1.19.2",
21 | "sequelize": "^6.29.0",
22 | "sqlite3": "^4.0.9"
23 | },
24 | "devDependencies": {
25 | "apollo": "^2.1.8",
26 | "apollo-link": "^1.2.3",
27 | "apollo-link-http": "^1.5.5",
28 | "jest": "^27.0.6",
29 | "nock": "^10.0.2",
30 | "node-fetch": "^2.2.1",
31 | "now": "^12.1.3"
32 | },
33 | "jest": {
34 | "testPathIgnorePatterns": [
35 | "/node_modules/",
36 | "/__utils"
37 | ]
38 | },
39 | "main": "src/index.js"
40 | }
41 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/src/__tests__/__snapshots__/e2e.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Server - e2e gets a single launch 1`] = `
4 | Object {
5 | "data": Object {
6 | "launch": Object {
7 | "id": "30",
8 | "isBooked": false,
9 | "mission": Object {
10 | "name": "Thaicom 8",
11 | },
12 | "rocket": Object {
13 | "type": "FT",
14 | },
15 | },
16 | },
17 | }
18 | `;
19 |
20 | exports[`Server - e2e gets list of launches 1`] = `
21 | Object {
22 | "data": Object {
23 | "launches": Object {
24 | "cursor": "1517433900",
25 | "launches": Array [
26 | Object {
27 | "mission": Object {
28 | "missionPatch": "https://images2.imgbox.com/42/0a/LAupFe3L_o.png",
29 | "name": "SES-16 / GovSat-1",
30 | },
31 | },
32 | ],
33 | },
34 | },
35 | }
36 | `;
37 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/src/__tests__/resolvers.mission.js:
--------------------------------------------------------------------------------
1 | const resolvers = require("../resolvers")
2 |
3 | const mockMission = {
4 | name: "foo",
5 | missionPatchLarge: "LG",
6 | missionPatchSmall: "SM"
7 | }
8 |
9 | describe("[Mission.missionPatch]", () => {
10 | it("chooses the right sized patch", () => {
11 | const { missionPatch } = resolvers.Mission
12 |
13 | // default -- no arg passed
14 | const resDefault = missionPatch(mockMission)
15 | const resSmall = missionPatch(mockMission, { size: "SMALL" })
16 | const resLarge = missionPatch(mockMission, { size: "LARGE" })
17 |
18 | expect(resDefault).toEqual("LG")
19 | expect(resSmall).toEqual("SM")
20 | expect(resLarge).toEqual("LG")
21 | })
22 | })
23 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/src/__tests__/resolvers.user.js:
--------------------------------------------------------------------------------
1 | const resolvers = require("../resolvers")
2 |
3 | describe("[User.trips]", () => {
4 | const mockContext = {
5 | dataSources: {
6 | userAPI: { getLaunchIdsByUser: jest.fn() },
7 | launchAPI: { getLaunchesByIds: jest.fn() }
8 | },
9 | user: { id: 1 }
10 | }
11 | const { getLaunchIdsByUser } = mockContext.dataSources.userAPI
12 | const { getLaunchesByIds } = mockContext.dataSources.launchAPI
13 |
14 | it("uses user id from context to lookup trips", async () => {
15 | getLaunchIdsByUser.mockReturnValueOnce([999])
16 | getLaunchesByIds.mockReturnValueOnce([{ id: 999 }])
17 |
18 | // check the resolver response
19 | const res = await resolvers.User.trips(null, null, mockContext)
20 | expect(res).toEqual([{ id: 999 }])
21 |
22 | // make sure the dataSources were called properly
23 | expect(getLaunchIdsByUser).toBeCalled()
24 | expect(getLaunchesByIds).toBeCalledWith({ launchIds: [999] })
25 | })
26 |
27 | it("returns empty array if no response", async () => {
28 | getLaunchIdsByUser.mockReturnValueOnce([])
29 | getLaunchesByIds.mockReturnValueOnce([])
30 |
31 | // check the resolver response
32 | const res = await resolvers.User.trips(null, null, mockContext)
33 | expect(res).toEqual([])
34 | })
35 | })
36 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/src/engine-demo.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | schemaTag: "current",
3 | generateClientInfo: ({ request }) => {
4 | if (!request || !request.http) return {}
5 | const clientName = request.http.headers.get("client-name")
6 | const clientVersion = request.http.headers.get("client-version")
7 | return { clientName, clientVersion }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/examples/4-apollo-tutorial/server/store.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mobxjs/mst-gql/ab8bd37c3cacebd6905b4842d2472cbcec1fb09e/examples/4-apollo-tutorial/server/store.sqlite
--------------------------------------------------------------------------------
/examples/5-nextjs/README.md:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | This example shows a minimal example of how to use SSR:
4 |
5 | ## Usage
6 |
7 | #### 0. install `mst-gql` dependencies (within the parent `mst-gql` directory)
8 |
9 | ```bash
10 | yarn
11 | ```
12 |
13 | #### 1. Install dependencies (within this example's folder)
14 |
15 | ```bash
16 | yarn
17 | ```
18 |
19 | #### 2. Start development server
20 |
21 | ```bash
22 | yarn dev
23 | ```
24 |
25 | #### 3. Run scaffold task
26 |
27 | (with development server running from previous step)
28 |
29 | ```bash
30 | yarn scaffold
31 | ```
32 |
--------------------------------------------------------------------------------
/examples/5-nextjs/components/users.tsx:
--------------------------------------------------------------------------------
1 | import { observer } from "mobx-react"
2 | import { useQuery } from "../src/models"
3 |
4 | // this component declares it's own data dependencies, and is only rendered client-side (uses noSsr)
5 | export const UsersView = observer(({}) => {
6 | const { error, data, loading, query } = useQuery((store) => {
7 | return store.queryUsers({}, (user) => user.name.likes, { noSsr: true })
8 | })
9 | if (error) return error.message
10 | if (!data) return "Loading..."
11 | return (
12 | <>
13 |
14 | {data.users.map((user) => (
15 | -
16 | {user.name}
17 | (likes: {user.likes!.join(" + ")})
18 |
19 | ))}
20 |
21 | {loading ? (
22 | "Loading..."
23 | ) : (
24 |
25 | )}
26 | >
27 | )
28 | })
29 |
30 | // this component also declares it's own data dependencies, but is rendered server-side
31 | // it's only rendered after the query in parent AllTodosView or DoneTodosView is done loading
32 | export const UserPreview = observer(({ userId }) => {
33 | const { error, data } = useQuery((store) => {
34 | return store.queryUser({ id: userId }, (user) => user.name)
35 | })
36 | if (error) return error.message
37 | if (!data) return "Loading..."
38 | return {data.user.name}
39 | })
40 |
--------------------------------------------------------------------------------
/examples/5-nextjs/mst-gql.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | format: "ts",
3 | input: "http://localhost:3000/api/graphql",
4 | outDir: "src/models",
5 | roots: ["Todo", "User"]
6 | }
7 |
--------------------------------------------------------------------------------
/examples/5-nextjs/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | // NOTE: This file should not be edited
5 | // see https://nextjs.org/docs/basic-features/typescript for more information.
6 |
--------------------------------------------------------------------------------
/examples/5-nextjs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ssr-example",
3 | "scripts": {
4 | "build": "next build",
5 | "dev": "nodemon --watch server server/index.js",
6 | "scaffold": "../../generator/mst-gql-scaffold.js",
7 | "start": "cross-env NODE_ENV=production node server/index.js"
8 | },
9 | "dependencies": {
10 | "apollo-server-express": "^2.18.0",
11 | "cross-env": "^5.2.1",
12 | "express": "^4.17.1",
13 | "graphql": "15.8.0",
14 | "mobx": "^6.10.2",
15 | "mobx-react": "^7.5.0",
16 | "mobx-state-tree": "^5.3.0",
17 | "mst-gql": "portal:../../",
18 | "next": "^13.5.0"
19 | },
20 | "devDependencies": {
21 | "@types/react": "^18.0.15",
22 | "@types/react-dom": "^18.0.6",
23 | "nodemon": "^1.19.2",
24 | "react": "^18.2.0",
25 | "react-dom": "^18.2.0",
26 | "typescript": "^4.7.3"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/examples/5-nextjs/pages/index.tsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react"
2 | import { AllTodosView, DoneTodosView } from "../components/todos"
3 | import { UsersView } from "../components/users"
4 |
5 | export default function Index() {
6 | const [showDoneTodos, setShowDoneTodos] = useState(true)
7 | return (
8 | <>
9 | All Todos
10 |
11 |
12 | Done Todos
13 |
16 | {showDoneTodos && }
17 |
18 | Users (query with no SSR)
19 |
20 | >
21 | )
22 | }
23 |
--------------------------------------------------------------------------------
/examples/5-nextjs/pages/other.tsx:
--------------------------------------------------------------------------------
1 | import Link from "next/link"
2 |
3 | export default function Other() {
4 | return (
5 |
6 | Navigate to index page with fully client-side rendering
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/examples/5-nextjs/server/index.js:
--------------------------------------------------------------------------------
1 | const { promisify } = require("util")
2 | const express = require("express")
3 | const { ApolloServer } = require("apollo-server-express")
4 | const next = require("next")
5 | const { resolvers, typeDefs } = require("./schema")
6 |
7 | const dev = process.env.NODE_ENV !== "production"
8 | const port = parseInt(process.env.PORT, 10) || 3000
9 |
10 | async function main() {
11 | const expressServer = express()
12 |
13 | const apolloServer = new ApolloServer({ typeDefs, resolvers })
14 | apolloServer.applyMiddleware({
15 | app: expressServer,
16 | path: "/api/graphql"
17 | })
18 |
19 | const nextServer = next({ dev })
20 | await nextServer.prepare()
21 | expressServer.all("*", nextServer.getRequestHandler())
22 |
23 | const listenFn = promisify(expressServer.listen.bind(expressServer))
24 | await listenFn(port)
25 | console.log(`> Ready on http://localhost:${port}`)
26 | }
27 |
28 | main().catch((error) => {
29 | console.error(error)
30 | process.exit(1)
31 | })
32 |
--------------------------------------------------------------------------------
/examples/5-nextjs/server/schema.js:
--------------------------------------------------------------------------------
1 | const { store } = require("./store")
2 |
3 | const typeDefs = `
4 | type Query {
5 | todos: [Todo]!,
6 | doneTodos: [Todo]!,
7 | user(id: ID!): User,
8 | users: [User]!,
9 | }
10 | type Mutation {
11 | toggleTodo(id: ID!): Todo,
12 | }
13 | type Todo {
14 | id: ID!,
15 | text: String!,
16 | done: Boolean!,
17 | assignee: User,
18 | }
19 | type User {
20 | id: ID!,
21 | name: String!,
22 | likes: [String]!,
23 | unobservedProp: String
24 | }
25 | `
26 |
27 | const resolvers = {
28 | Query: {
29 | todos: () => {
30 | return store.todos
31 | },
32 | doneTodos: () => {
33 | return store.todos.filter((todo) => todo.done)
34 | },
35 | user: (root, args) => {
36 | return store.users.find((user) => user.id === args.id)
37 | },
38 | users: () => {
39 | return store.users
40 | }
41 | },
42 | Mutation: {
43 | toggleTodo: (root, args) => {
44 | const todo = store.todos.find((todo) => todo.id === args.id)
45 | todo.done = !todo.done
46 | return todo
47 | }
48 | },
49 | Todo: {
50 | assignee: (todo) => {
51 | return store.users.find((user) => user.id === todo.assignee)
52 | }
53 | },
54 | User: {
55 | unobservedProp: (user) => {
56 | return "foo"
57 | }
58 | }
59 | }
60 |
61 | module.exports = {
62 | typeDefs,
63 | resolvers
64 | }
65 |
--------------------------------------------------------------------------------
/examples/5-nextjs/server/store.js:
--------------------------------------------------------------------------------
1 | const store = {
2 | todos: [
3 | {
4 | id: "0",
5 | text: "Go to the shops",
6 | done: false,
7 | assignee: "rsanchez"
8 | },
9 | {
10 | id: "1",
11 | text: "Pick up the kids",
12 | done: true,
13 | assignee: null
14 | },
15 | {
16 | id: "2",
17 | text: "Install mst-gql",
18 | done: true,
19 | assignee: "msmith"
20 | }
21 | ],
22 | users: [
23 | {
24 | id: "rsanchez",
25 | name: "Rick Sanchez",
26 | likes: ["computers", "Kalaxian Crystals"]
27 | },
28 | {
29 | id: "msmith",
30 | name: "Morty Smith",
31 | likes: ["Jessica"]
32 | }
33 | ]
34 | }
35 |
36 | // Force frequently changing data in user
37 | /* setInterval(() => {
38 | store.users.forEach(user => {
39 | user.name = user.name.split(' ').reverse().join(' ')
40 | })
41 | }, 500) */
42 |
43 | module.exports = { store }
44 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/ModelBase.ts:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 | import { types } from "mobx-state-tree"
3 |
4 | export const ModelBase = MSTGQLObject.props({
5 | $created: types.optional(types.Date, () => new Date())
6 | })
7 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/RootStore.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { RootStoreBase } from "./RootStore.base"
3 |
4 | export interface RootStoreType extends Instance {}
5 |
6 | export const RootStore = RootStoreBase
7 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/TodoModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { TodoModelBase } from "./TodoModel.base"
3 |
4 | /* The TypeScript type of an instance of TodoModel */
5 | export interface TodoModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for TodoModel */
8 | export {
9 | selectFromTodo,
10 | todoModelPrimitives,
11 | TodoModelSelector
12 | } from "./TodoModel.base"
13 |
14 | /**
15 | * TodoModel
16 | */
17 | export const TodoModel = TodoModelBase.actions((self) => ({
18 | toggle() {
19 | return self.store.mutateToggleTodo(
20 | { id: self.id },
21 | (todo) => todo.done,
22 | () => {
23 | self.done = !self.done
24 | }
25 | )
26 | }
27 | }))
28 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/UserModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * UserBase
13 | * auto generated base class for the model UserModel.
14 | */
15 | export const UserModelBase = ModelBase
16 | .named('User')
17 | .props({
18 | __typename: types.optional(types.literal("User"), "User"),
19 | id: types.identifier,
20 | name: types.union(types.undefined, types.string),
21 | likes: types.union(types.undefined, types.array(types.union(types.null, types.string))),
22 | unobservedProp: types.union(types.undefined, types.null, types.string),
23 | })
24 | .views(self => ({
25 | get store() {
26 | return self.__getStore()
27 | }
28 | }))
29 |
30 | export class UserModelSelector extends QueryBuilder {
31 | get id() { return this.__attr(`id`) }
32 | get name() { return this.__attr(`name`) }
33 | get likes() { return this.__attr(`likes`) }
34 | get unobservedProp() { return this.__attr(`unobservedProp`) }
35 | }
36 | export function selectFromUser() {
37 | return new UserModelSelector()
38 | }
39 |
40 | export const userModelPrimitives = selectFromUser().name.likes.unobservedProp
41 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/UserModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { UserModelBase } from "./UserModel.base"
3 |
4 | /* The TypeScript type of an instance of UserModel */
5 | export interface UserModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for UserModel */
8 | export {
9 | selectFromUser,
10 | userModelPrimitives,
11 | UserModelSelector
12 | } from "./UserModel.base"
13 |
14 | /**
15 | * UserModel
16 | */
17 | export const UserModel = UserModelBase.actions((self) => ({}))
18 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/index.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | export * from "./TodoModel"
6 | export * from "./UserModel"
7 | export * from "./RootStore"
8 | export * from "./reactUtils"
9 |
--------------------------------------------------------------------------------
/examples/5-nextjs/src/models/reactUtils.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { createStoreContext, createUseQueryHook } from "mst-gql"
6 | import * as React from "react"
7 | import { RootStore, RootStoreType } from "./RootStore"
8 |
9 | export const StoreContext = createStoreContext(React)
10 |
11 | export const useQuery = createUseQueryHook(StoreContext, React)
12 |
--------------------------------------------------------------------------------
/examples/5-nextjs/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "esnext",
5 | "jsx": "preserve",
6 | "noEmit": true,
7 | "strict": true,
8 | "noImplicitAny": false,
9 | "strictNullChecks": true,
10 | "esModuleInterop": true,
11 | "lib": ["dom", "dom.iterable", "esnext"],
12 | "allowJs": true,
13 | "skipLibCheck": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "moduleResolution": "node",
16 | "resolveJsonModule": true,
17 | "isolatedModules": true,
18 | "incremental": true
19 | },
20 | "exclude": ["node_modules"],
21 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
22 | }
23 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/README.md:
--------------------------------------------------------------------------------
1 | ## About
2 |
3 | This example/test is used to validate generation of mst-models based on a somewhat complex Hasura generated schema (schema.graphql).
4 |
5 | ## Usage
6 |
7 | #### 0. install `mst-gql` dependencies (within the parent `mst-gql` directory)
8 |
9 | ```bash
10 | yarn
11 | ```
12 |
13 | #### 1. Install dependencies (within this example's folder)
14 |
15 | ```bash
16 | yarn
17 | ```
18 |
19 | #### 2. Scaffold
20 |
21 | ```bash
22 | yarn start
23 | ```
24 |
25 | Runs the scaffolder and uses TypeScript to compile the generated sources.
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/mst-gql.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | force: true,
3 | format: "ts",
4 | input: "schema.graphql",
5 | outDir: "src/models"
6 | // roots: ["Pokemon", "Attack"]
7 | }
8 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@mst-gql/scaffold-test-hasura",
3 | "scripts": {
4 | "build": "tsc",
5 | "scaffold": "../../generator/mst-gql-scaffold.js",
6 | "start": "yarn scaffold && yarn build"
7 | },
8 | "dependencies": {
9 | "graphql": "^16.8.1",
10 | "graphql-request": "^4.3.0",
11 | "mobx": "^6.10.2",
12 | "mobx-state-tree": "^5.3.0",
13 | "mst-gql": "portal:../../"
14 | },
15 | "devDependencies": {
16 | "@types/react": "^18.0.15",
17 | "@types/react-dom": "^18.0.6",
18 | "react": "^18.2.0",
19 | "react-dom": "^18.2.0",
20 | "typescript": "^4.7.3"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesAggregateFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesAggregateFieldsModelBase } from "./ChoicesAggregateFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesAggregateFieldsModel */
5 | export interface ChoicesAggregateFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesAggregateFieldsModel */
9 | export {
10 | selectFromChoicesAggregateFields,
11 | choicesAggregateFieldsModelPrimitives,
12 | ChoicesAggregateFieldsModelSelector
13 | } from "./ChoicesAggregateFieldsModel.base"
14 |
15 | /**
16 | * ChoicesAggregateFieldsModel
17 | */
18 | export const ChoicesAggregateFieldsModel =
19 | ChoicesAggregateFieldsModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesAggregateModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesAggregateModelBase } from "./ChoicesAggregateModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesAggregateModel */
5 | export interface ChoicesAggregateModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesAggregateModel */
9 | export {
10 | selectFromChoicesAggregate,
11 | choicesAggregateModelPrimitives,
12 | ChoicesAggregateModelSelector
13 | } from "./ChoicesAggregateModel.base"
14 |
15 | /**
16 | * ChoicesAggregateModel
17 | */
18 | export const ChoicesAggregateModel = ChoicesAggregateModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesAvgFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesAvgFieldsBase
13 | * auto generated base class for the model ChoicesAvgFieldsModel.
14 | */
15 | export const ChoicesAvgFieldsModelBase = ModelBase
16 | .named('ChoicesAvgFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_avg_fields"), "choices_avg_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesAvgFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesAvgFields() {
33 | return new ChoicesAvgFieldsModelSelector()
34 | }
35 |
36 | export const choicesAvgFieldsModelPrimitives = selectFromChoicesAvgFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesAvgFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesAvgFieldsModelBase } from "./ChoicesAvgFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesAvgFieldsModel */
5 | export interface ChoicesAvgFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesAvgFieldsModel */
9 | export {
10 | selectFromChoicesAvgFields,
11 | choicesAvgFieldsModelPrimitives,
12 | ChoicesAvgFieldsModelSelector
13 | } from "./ChoicesAvgFieldsModel.base"
14 |
15 | /**
16 | * ChoicesAvgFieldsModel
17 | */
18 | export const ChoicesAvgFieldsModel = ChoicesAvgFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesConstraintEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum ChoicesConstraint {
11 | choices_pkey="choices_pkey"
12 | }
13 |
14 | /**
15 | * ChoicesConstraint
16 | */
17 | export const ChoicesConstraintEnumType = types.enumeration("ChoicesConstraint", [
18 | "choices_pkey",
19 | ])
20 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesMaxFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesMaxFieldsBase
13 | * auto generated base class for the model ChoicesMaxFieldsModel.
14 | */
15 | export const ChoicesMaxFieldsModelBase = ModelBase
16 | .named('ChoicesMaxFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_max_fields"), "choices_max_fields"),
19 | id: types.union(types.undefined, types.null, types.frozen()),
20 | poll_id: types.union(types.undefined, types.null, types.frozen()),
21 | text: types.union(types.undefined, types.null, types.string),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class ChoicesMaxFieldsModelSelector extends QueryBuilder {
30 | get id() { return this.__attr(`id`) }
31 | get poll_id() { return this.__attr(`poll_id`) }
32 | get text() { return this.__attr(`text`) }
33 | }
34 | export function selectFromChoicesMaxFields() {
35 | return new ChoicesMaxFieldsModelSelector()
36 | }
37 |
38 | export const choicesMaxFieldsModelPrimitives = selectFromChoicesMaxFields().poll_id.text
39 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesMaxFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesMaxFieldsModelBase } from "./ChoicesMaxFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesMaxFieldsModel */
5 | export interface ChoicesMaxFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesMaxFieldsModel */
9 | export {
10 | selectFromChoicesMaxFields,
11 | choicesMaxFieldsModelPrimitives,
12 | ChoicesMaxFieldsModelSelector
13 | } from "./ChoicesMaxFieldsModel.base"
14 |
15 | /**
16 | * ChoicesMaxFieldsModel
17 | */
18 | export const ChoicesMaxFieldsModel = ChoicesMaxFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesMinFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesMinFieldsBase
13 | * auto generated base class for the model ChoicesMinFieldsModel.
14 | */
15 | export const ChoicesMinFieldsModelBase = ModelBase
16 | .named('ChoicesMinFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_min_fields"), "choices_min_fields"),
19 | id: types.union(types.undefined, types.null, types.frozen()),
20 | poll_id: types.union(types.undefined, types.null, types.frozen()),
21 | text: types.union(types.undefined, types.null, types.string),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class ChoicesMinFieldsModelSelector extends QueryBuilder {
30 | get id() { return this.__attr(`id`) }
31 | get poll_id() { return this.__attr(`poll_id`) }
32 | get text() { return this.__attr(`text`) }
33 | }
34 | export function selectFromChoicesMinFields() {
35 | return new ChoicesMinFieldsModelSelector()
36 | }
37 |
38 | export const choicesMinFieldsModelPrimitives = selectFromChoicesMinFields().poll_id.text
39 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesMinFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesMinFieldsModelBase } from "./ChoicesMinFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesMinFieldsModel */
5 | export interface ChoicesMinFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesMinFieldsModel */
9 | export {
10 | selectFromChoicesMinFields,
11 | choicesMinFieldsModelPrimitives,
12 | ChoicesMinFieldsModelSelector
13 | } from "./ChoicesMinFieldsModel.base"
14 |
15 | /**
16 | * ChoicesMinFieldsModel
17 | */
18 | export const ChoicesMinFieldsModel = ChoicesMinFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesModelBase } from "./ChoicesModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesModel */
5 | export interface ChoicesModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for ChoicesModel */
8 | export {
9 | selectFromChoices,
10 | choicesModelPrimitives,
11 | ChoicesModelSelector
12 | } from "./ChoicesModel.base"
13 |
14 | /**
15 | * ChoicesModel
16 | */
17 | export const ChoicesModel = ChoicesModelBase.actions((self) => ({
18 | // This is an auto-generated example action.
19 | log() {
20 | console.log(JSON.stringify(self))
21 | }
22 | }))
23 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesMutationResponseModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesMutationResponseModelBase } from "./ChoicesMutationResponseModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesMutationResponseModel */
5 | export interface ChoicesMutationResponseModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesMutationResponseModel */
9 | export {
10 | selectFromChoicesMutationResponse,
11 | choicesMutationResponseModelPrimitives,
12 | ChoicesMutationResponseModelSelector
13 | } from "./ChoicesMutationResponseModel.base"
14 |
15 | /**
16 | * ChoicesMutationResponseModel
17 | */
18 | export const ChoicesMutationResponseModel =
19 | ChoicesMutationResponseModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesSelectColumnEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum ChoicesSelectColumn {
11 | id="id",
12 | poll_id="poll_id",
13 | text="text"
14 | }
15 |
16 | /**
17 | * ChoicesSelectColumn
18 | */
19 | export const ChoicesSelectColumnEnumType = types.enumeration("ChoicesSelectColumn", [
20 | "id",
21 | "poll_id",
22 | "text",
23 | ])
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesStddevFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesStddevFieldsBase
13 | * auto generated base class for the model ChoicesStddevFieldsModel.
14 | */
15 | export const ChoicesStddevFieldsModelBase = ModelBase
16 | .named('ChoicesStddevFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_stddev_fields"), "choices_stddev_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesStddevFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesStddevFields() {
33 | return new ChoicesStddevFieldsModelSelector()
34 | }
35 |
36 | export const choicesStddevFieldsModelPrimitives = selectFromChoicesStddevFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesStddevFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesStddevFieldsModelBase } from "./ChoicesStddevFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesStddevFieldsModel */
5 | export interface ChoicesStddevFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesStddevFieldsModel */
9 | export {
10 | selectFromChoicesStddevFields,
11 | choicesStddevFieldsModelPrimitives,
12 | ChoicesStddevFieldsModelSelector
13 | } from "./ChoicesStddevFieldsModel.base"
14 |
15 | /**
16 | * ChoicesStddevFieldsModel
17 | */
18 | export const ChoicesStddevFieldsModel = ChoicesStddevFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesStddevPopFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesStddevPopFieldsBase
13 | * auto generated base class for the model ChoicesStddevPopFieldsModel.
14 | */
15 | export const ChoicesStddevPopFieldsModelBase = ModelBase
16 | .named('ChoicesStddevPopFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_stddev_pop_fields"), "choices_stddev_pop_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesStddevPopFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesStddevPopFields() {
33 | return new ChoicesStddevPopFieldsModelSelector()
34 | }
35 |
36 | export const choicesStddevPopFieldsModelPrimitives = selectFromChoicesStddevPopFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesStddevPopFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesStddevPopFieldsModelBase } from "./ChoicesStddevPopFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesStddevPopFieldsModel */
5 | export interface ChoicesStddevPopFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesStddevPopFieldsModel */
9 | export {
10 | selectFromChoicesStddevPopFields,
11 | choicesStddevPopFieldsModelPrimitives,
12 | ChoicesStddevPopFieldsModelSelector
13 | } from "./ChoicesStddevPopFieldsModel.base"
14 |
15 | /**
16 | * ChoicesStddevPopFieldsModel
17 | */
18 | export const ChoicesStddevPopFieldsModel =
19 | ChoicesStddevPopFieldsModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesStddevSampFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesStddevSampFieldsBase
13 | * auto generated base class for the model ChoicesStddevSampFieldsModel.
14 | */
15 | export const ChoicesStddevSampFieldsModelBase = ModelBase
16 | .named('ChoicesStddevSampFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_stddev_samp_fields"), "choices_stddev_samp_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesStddevSampFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesStddevSampFields() {
33 | return new ChoicesStddevSampFieldsModelSelector()
34 | }
35 |
36 | export const choicesStddevSampFieldsModelPrimitives = selectFromChoicesStddevSampFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesStddevSampFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesStddevSampFieldsModelBase } from "./ChoicesStddevSampFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesStddevSampFieldsModel */
5 | export interface ChoicesStddevSampFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesStddevSampFieldsModel */
9 | export {
10 | selectFromChoicesStddevSampFields,
11 | choicesStddevSampFieldsModelPrimitives,
12 | ChoicesStddevSampFieldsModelSelector
13 | } from "./ChoicesStddevSampFieldsModel.base"
14 |
15 | /**
16 | * ChoicesStddevSampFieldsModel
17 | */
18 | export const ChoicesStddevSampFieldsModel =
19 | ChoicesStddevSampFieldsModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesSumFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesSumFieldsBase
13 | * auto generated base class for the model ChoicesSumFieldsModel.
14 | */
15 | export const ChoicesSumFieldsModelBase = ModelBase
16 | .named('ChoicesSumFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_sum_fields"), "choices_sum_fields"),
19 | id: types.union(types.undefined, types.null, types.frozen()),
20 | poll_id: types.union(types.undefined, types.null, types.frozen()),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesSumFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesSumFields() {
33 | return new ChoicesSumFieldsModelSelector()
34 | }
35 |
36 | export const choicesSumFieldsModelPrimitives = selectFromChoicesSumFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesSumFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesSumFieldsModelBase } from "./ChoicesSumFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesSumFieldsModel */
5 | export interface ChoicesSumFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesSumFieldsModel */
9 | export {
10 | selectFromChoicesSumFields,
11 | choicesSumFieldsModelPrimitives,
12 | ChoicesSumFieldsModelSelector
13 | } from "./ChoicesSumFieldsModel.base"
14 |
15 | /**
16 | * ChoicesSumFieldsModel
17 | */
18 | export const ChoicesSumFieldsModel = ChoicesSumFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesUpdateColumnEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum ChoicesUpdateColumn {
11 | id="id",
12 | poll_id="poll_id",
13 | text="text"
14 | }
15 |
16 | /**
17 | * ChoicesUpdateColumn
18 | */
19 | export const ChoicesUpdateColumnEnumType = types.enumeration("ChoicesUpdateColumn", [
20 | "id",
21 | "poll_id",
22 | "text",
23 | ])
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesVarPopFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesVarPopFieldsBase
13 | * auto generated base class for the model ChoicesVarPopFieldsModel.
14 | */
15 | export const ChoicesVarPopFieldsModelBase = ModelBase
16 | .named('ChoicesVarPopFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_var_pop_fields"), "choices_var_pop_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesVarPopFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesVarPopFields() {
33 | return new ChoicesVarPopFieldsModelSelector()
34 | }
35 |
36 | export const choicesVarPopFieldsModelPrimitives = selectFromChoicesVarPopFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesVarPopFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesVarPopFieldsModelBase } from "./ChoicesVarPopFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesVarPopFieldsModel */
5 | export interface ChoicesVarPopFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesVarPopFieldsModel */
9 | export {
10 | selectFromChoicesVarPopFields,
11 | choicesVarPopFieldsModelPrimitives,
12 | ChoicesVarPopFieldsModelSelector
13 | } from "./ChoicesVarPopFieldsModel.base"
14 |
15 | /**
16 | * ChoicesVarPopFieldsModel
17 | */
18 | export const ChoicesVarPopFieldsModel = ChoicesVarPopFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesVarSampFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesVarSampFieldsBase
13 | * auto generated base class for the model ChoicesVarSampFieldsModel.
14 | */
15 | export const ChoicesVarSampFieldsModelBase = ModelBase
16 | .named('ChoicesVarSampFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_var_samp_fields"), "choices_var_samp_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesVarSampFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesVarSampFields() {
33 | return new ChoicesVarSampFieldsModelSelector()
34 | }
35 |
36 | export const choicesVarSampFieldsModelPrimitives = selectFromChoicesVarSampFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesVarSampFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesVarSampFieldsModelBase } from "./ChoicesVarSampFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesVarSampFieldsModel */
5 | export interface ChoicesVarSampFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesVarSampFieldsModel */
9 | export {
10 | selectFromChoicesVarSampFields,
11 | choicesVarSampFieldsModelPrimitives,
12 | ChoicesVarSampFieldsModelSelector
13 | } from "./ChoicesVarSampFieldsModel.base"
14 |
15 | /**
16 | * ChoicesVarSampFieldsModel
17 | */
18 | export const ChoicesVarSampFieldsModel = ChoicesVarSampFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesVarianceFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * ChoicesVarianceFieldsBase
13 | * auto generated base class for the model ChoicesVarianceFieldsModel.
14 | */
15 | export const ChoicesVarianceFieldsModelBase = ModelBase
16 | .named('ChoicesVarianceFields')
17 | .props({
18 | __typename: types.optional(types.literal("choices_variance_fields"), "choices_variance_fields"),
19 | id: types.union(types.undefined, types.null, types.number),
20 | poll_id: types.union(types.undefined, types.null, types.number),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class ChoicesVarianceFieldsModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get poll_id() { return this.__attr(`poll_id`) }
31 | }
32 | export function selectFromChoicesVarianceFields() {
33 | return new ChoicesVarianceFieldsModelSelector()
34 | }
35 |
36 | export const choicesVarianceFieldsModelPrimitives = selectFromChoicesVarianceFields().poll_id
37 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ChoicesVarianceFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { ChoicesVarianceFieldsModelBase } from "./ChoicesVarianceFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of ChoicesVarianceFieldsModel */
5 | export interface ChoicesVarianceFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for ChoicesVarianceFieldsModel */
9 | export {
10 | selectFromChoicesVarianceFields,
11 | choicesVarianceFieldsModelPrimitives,
12 | ChoicesVarianceFieldsModelSelector
13 | } from "./ChoicesVarianceFieldsModel.base"
14 |
15 | /**
16 | * ChoicesVarianceFieldsModel
17 | */
18 | export const ChoicesVarianceFieldsModel =
19 | ChoicesVarianceFieldsModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ConflictActionEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum ConflictAction {
11 | ignore="ignore",
12 | update="update"
13 | }
14 |
15 | /**
16 | * ConflictAction
17 | */
18 | export const ConflictActionEnumType = types.enumeration("ConflictAction", [
19 | "ignore",
20 | "update",
21 | ])
22 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/ModelBase.ts:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/MutationRootModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { MutationRootModelBase } from "./MutationRootModel.base"
3 |
4 | /* The TypeScript type of an instance of MutationRootModel */
5 | export interface MutationRootModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for MutationRootModel */
9 | export {
10 | selectFromMutationRoot,
11 | mutationRootModelPrimitives,
12 | MutationRootModelSelector
13 | } from "./MutationRootModel.base"
14 |
15 | /**
16 | * MutationRootModel
17 | */
18 | export const MutationRootModel = MutationRootModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/OrderByEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum OrderBy {
11 | asc="asc",
12 | asc_nulls_first="asc_nulls_first",
13 | asc_nulls_last="asc_nulls_last",
14 | desc="desc",
15 | desc_nulls_first="desc_nulls_first",
16 | desc_nulls_last="desc_nulls_last"
17 | }
18 |
19 | /**
20 | * OrderBy
21 | */
22 | export const OrderByEnumType = types.enumeration("OrderBy", [
23 | "asc",
24 | "asc_nulls_first",
25 | "asc_nulls_last",
26 | "desc",
27 | "desc_nulls_first",
28 | "desc_nulls_last",
29 | ])
30 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsAggregateFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsAggregateFieldsModelBase } from "./PollsAggregateFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsAggregateFieldsModel */
5 | export interface PollsAggregateFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsAggregateFieldsModel */
9 | export {
10 | selectFromPollsAggregateFields,
11 | pollsAggregateFieldsModelPrimitives,
12 | PollsAggregateFieldsModelSelector
13 | } from "./PollsAggregateFieldsModel.base"
14 |
15 | /**
16 | * PollsAggregateFieldsModel
17 | */
18 | export const PollsAggregateFieldsModel = PollsAggregateFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsAggregateModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsAggregateModelBase } from "./PollsAggregateModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsAggregateModel */
5 | export interface PollsAggregateModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsAggregateModel */
9 | export {
10 | selectFromPollsAggregate,
11 | pollsAggregateModelPrimitives,
12 | PollsAggregateModelSelector
13 | } from "./PollsAggregateModel.base"
14 |
15 | /**
16 | * PollsAggregateModel
17 | */
18 | export const PollsAggregateModel = PollsAggregateModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsAvgFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * PollsAvgFieldsBase
13 | * auto generated base class for the model PollsAvgFieldsModel.
14 | */
15 | export const PollsAvgFieldsModelBase = ModelBase
16 | .named('PollsAvgFields')
17 | .props({
18 | __typename: types.optional(types.literal("polls_avg_fields"), "polls_avg_fields"),
19 | created_by: types.union(types.undefined, types.null, types.number),
20 | id: types.union(types.undefined, types.null, types.number),
21 | updated_by: types.union(types.undefined, types.null, types.number),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class PollsAvgFieldsModelSelector extends QueryBuilder {
30 | get created_by() { return this.__attr(`created_by`) }
31 | get id() { return this.__attr(`id`) }
32 | get updated_by() { return this.__attr(`updated_by`) }
33 | }
34 | export function selectFromPollsAvgFields() {
35 | return new PollsAvgFieldsModelSelector()
36 | }
37 |
38 | export const pollsAvgFieldsModelPrimitives = selectFromPollsAvgFields().created_by.updated_by
39 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsAvgFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsAvgFieldsModelBase } from "./PollsAvgFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsAvgFieldsModel */
5 | export interface PollsAvgFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsAvgFieldsModel */
9 | export {
10 | selectFromPollsAvgFields,
11 | pollsAvgFieldsModelPrimitives,
12 | PollsAvgFieldsModelSelector
13 | } from "./PollsAvgFieldsModel.base"
14 |
15 | /**
16 | * PollsAvgFieldsModel
17 | */
18 | export const PollsAvgFieldsModel = PollsAvgFieldsModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsConstraintEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum PollsConstraint {
11 | polls_pkey="polls_pkey"
12 | }
13 |
14 | /**
15 | * PollsConstraint
16 | */
17 | export const PollsConstraintEnumType = types.enumeration("PollsConstraint", [
18 | "polls_pkey",
19 | ])
20 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsMaxFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsMaxFieldsModelBase } from "./PollsMaxFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsMaxFieldsModel */
5 | export interface PollsMaxFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsMaxFieldsModel */
9 | export {
10 | selectFromPollsMaxFields,
11 | pollsMaxFieldsModelPrimitives,
12 | PollsMaxFieldsModelSelector
13 | } from "./PollsMaxFieldsModel.base"
14 |
15 | /**
16 | * PollsMaxFieldsModel
17 | */
18 | export const PollsMaxFieldsModel = PollsMaxFieldsModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsMinFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsMinFieldsModelBase } from "./PollsMinFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsMinFieldsModel */
5 | export interface PollsMinFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsMinFieldsModel */
9 | export {
10 | selectFromPollsMinFields,
11 | pollsMinFieldsModelPrimitives,
12 | PollsMinFieldsModelSelector
13 | } from "./PollsMinFieldsModel.base"
14 |
15 | /**
16 | * PollsMinFieldsModel
17 | */
18 | export const PollsMinFieldsModel = PollsMinFieldsModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsModelBase } from "./PollsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsModel */
5 | export interface PollsModelType extends Instance {}
6 |
7 | /* A graphql query fragment builders for PollsModel */
8 | export {
9 | selectFromPolls,
10 | pollsModelPrimitives,
11 | PollsModelSelector
12 | } from "./PollsModel.base"
13 |
14 | /**
15 | * PollsModel
16 | */
17 | export const PollsModel = PollsModelBase.actions((self) => ({
18 | // This is an auto-generated example action.
19 | log() {
20 | console.log(JSON.stringify(self))
21 | }
22 | }))
23 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsMutationResponseModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsMutationResponseModelBase } from "./PollsMutationResponseModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsMutationResponseModel */
5 | export interface PollsMutationResponseModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsMutationResponseModel */
9 | export {
10 | selectFromPollsMutationResponse,
11 | pollsMutationResponseModelPrimitives,
12 | PollsMutationResponseModelSelector
13 | } from "./PollsMutationResponseModel.base"
14 |
15 | /**
16 | * PollsMutationResponseModel
17 | */
18 | export const PollsMutationResponseModel =
19 | PollsMutationResponseModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsSelectColumnEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum PollsSelectColumn {
11 | created_at="created_at",
12 | created_by="created_by",
13 | expiration_date_time="expiration_date_time",
14 | foo="foo",
15 | id="id",
16 | ize="ize",
17 | question="question",
18 | updated_at="updated_at",
19 | updated_by="updated_by"
20 | }
21 |
22 | /**
23 | * PollsSelectColumn
24 | */
25 | export const PollsSelectColumnEnumType = types.enumeration("PollsSelectColumn", [
26 | "created_at",
27 | "created_by",
28 | "expiration_date_time",
29 | "foo",
30 | "id",
31 | "ize",
32 | "question",
33 | "updated_at",
34 | "updated_by",
35 | ])
36 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsStddevFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * PollsStddevFieldsBase
13 | * auto generated base class for the model PollsStddevFieldsModel.
14 | */
15 | export const PollsStddevFieldsModelBase = ModelBase
16 | .named('PollsStddevFields')
17 | .props({
18 | __typename: types.optional(types.literal("polls_stddev_fields"), "polls_stddev_fields"),
19 | created_by: types.union(types.undefined, types.null, types.number),
20 | id: types.union(types.undefined, types.null, types.number),
21 | updated_by: types.union(types.undefined, types.null, types.number),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class PollsStddevFieldsModelSelector extends QueryBuilder {
30 | get created_by() { return this.__attr(`created_by`) }
31 | get id() { return this.__attr(`id`) }
32 | get updated_by() { return this.__attr(`updated_by`) }
33 | }
34 | export function selectFromPollsStddevFields() {
35 | return new PollsStddevFieldsModelSelector()
36 | }
37 |
38 | export const pollsStddevFieldsModelPrimitives = selectFromPollsStddevFields().created_by.updated_by
39 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsStddevFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsStddevFieldsModelBase } from "./PollsStddevFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsStddevFieldsModel */
5 | export interface PollsStddevFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsStddevFieldsModel */
9 | export {
10 | selectFromPollsStddevFields,
11 | pollsStddevFieldsModelPrimitives,
12 | PollsStddevFieldsModelSelector
13 | } from "./PollsStddevFieldsModel.base"
14 |
15 | /**
16 | * PollsStddevFieldsModel
17 | */
18 | export const PollsStddevFieldsModel = PollsStddevFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsStddevPopFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsStddevPopFieldsModelBase } from "./PollsStddevPopFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsStddevPopFieldsModel */
5 | export interface PollsStddevPopFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsStddevPopFieldsModel */
9 | export {
10 | selectFromPollsStddevPopFields,
11 | pollsStddevPopFieldsModelPrimitives,
12 | PollsStddevPopFieldsModelSelector
13 | } from "./PollsStddevPopFieldsModel.base"
14 |
15 | /**
16 | * PollsStddevPopFieldsModel
17 | */
18 | export const PollsStddevPopFieldsModel = PollsStddevPopFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsStddevSampFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsStddevSampFieldsModelBase } from "./PollsStddevSampFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsStddevSampFieldsModel */
5 | export interface PollsStddevSampFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsStddevSampFieldsModel */
9 | export {
10 | selectFromPollsStddevSampFields,
11 | pollsStddevSampFieldsModelPrimitives,
12 | PollsStddevSampFieldsModelSelector
13 | } from "./PollsStddevSampFieldsModel.base"
14 |
15 | /**
16 | * PollsStddevSampFieldsModel
17 | */
18 | export const PollsStddevSampFieldsModel =
19 | PollsStddevSampFieldsModelBase.actions((self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | }))
25 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsSumFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * PollsSumFieldsBase
13 | * auto generated base class for the model PollsSumFieldsModel.
14 | */
15 | export const PollsSumFieldsModelBase = ModelBase
16 | .named('PollsSumFields')
17 | .props({
18 | __typename: types.optional(types.literal("polls_sum_fields"), "polls_sum_fields"),
19 | created_by: types.union(types.undefined, types.null, types.frozen()),
20 | id: types.union(types.undefined, types.null, types.frozen()),
21 | updated_by: types.union(types.undefined, types.null, types.frozen()),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class PollsSumFieldsModelSelector extends QueryBuilder {
30 | get created_by() { return this.__attr(`created_by`) }
31 | get id() { return this.__attr(`id`) }
32 | get updated_by() { return this.__attr(`updated_by`) }
33 | }
34 | export function selectFromPollsSumFields() {
35 | return new PollsSumFieldsModelSelector()
36 | }
37 |
38 | export const pollsSumFieldsModelPrimitives = selectFromPollsSumFields().created_by.updated_by
39 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsSumFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsSumFieldsModelBase } from "./PollsSumFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsSumFieldsModel */
5 | export interface PollsSumFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsSumFieldsModel */
9 | export {
10 | selectFromPollsSumFields,
11 | pollsSumFieldsModelPrimitives,
12 | PollsSumFieldsModelSelector
13 | } from "./PollsSumFieldsModel.base"
14 |
15 | /**
16 | * PollsSumFieldsModel
17 | */
18 | export const PollsSumFieldsModel = PollsSumFieldsModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsUpdateColumnEnum.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 | import { types } from "mobx-state-tree"
5 |
6 | /**
7 | * Typescript enum
8 | */
9 |
10 | export enum PollsUpdateColumn {
11 | created_at="created_at",
12 | created_by="created_by",
13 | expiration_date_time="expiration_date_time",
14 | foo="foo",
15 | id="id",
16 | ize="ize",
17 | question="question",
18 | updated_at="updated_at",
19 | updated_by="updated_by"
20 | }
21 |
22 | /**
23 | * PollsUpdateColumn
24 | */
25 | export const PollsUpdateColumnEnumType = types.enumeration("PollsUpdateColumn", [
26 | "created_at",
27 | "created_by",
28 | "expiration_date_time",
29 | "foo",
30 | "id",
31 | "ize",
32 | "question",
33 | "updated_at",
34 | "updated_by",
35 | ])
36 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsVarPopFieldsModel.base.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { types } from "mobx-state-tree"
6 | import { QueryBuilder } from "mst-gql"
7 | import { ModelBase } from "./ModelBase"
8 | import { RootStoreType } from "./index"
9 |
10 |
11 | /**
12 | * PollsVarPopFieldsBase
13 | * auto generated base class for the model PollsVarPopFieldsModel.
14 | */
15 | export const PollsVarPopFieldsModelBase = ModelBase
16 | .named('PollsVarPopFields')
17 | .props({
18 | __typename: types.optional(types.literal("polls_var_pop_fields"), "polls_var_pop_fields"),
19 | created_by: types.union(types.undefined, types.null, types.number),
20 | id: types.union(types.undefined, types.null, types.number),
21 | updated_by: types.union(types.undefined, types.null, types.number),
22 | })
23 | .views(self => ({
24 | get store() {
25 | return self.__getStore()
26 | }
27 | }))
28 |
29 | export class PollsVarPopFieldsModelSelector extends QueryBuilder {
30 | get created_by() { return this.__attr(`created_by`) }
31 | get id() { return this.__attr(`id`) }
32 | get updated_by() { return this.__attr(`updated_by`) }
33 | }
34 | export function selectFromPollsVarPopFields() {
35 | return new PollsVarPopFieldsModelSelector()
36 | }
37 |
38 | export const pollsVarPopFieldsModelPrimitives = selectFromPollsVarPopFields().created_by.updated_by
39 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsVarPopFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsVarPopFieldsModelBase } from "./PollsVarPopFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsVarPopFieldsModel */
5 | export interface PollsVarPopFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsVarPopFieldsModel */
9 | export {
10 | selectFromPollsVarPopFields,
11 | pollsVarPopFieldsModelPrimitives,
12 | PollsVarPopFieldsModelSelector
13 | } from "./PollsVarPopFieldsModel.base"
14 |
15 | /**
16 | * PollsVarPopFieldsModel
17 | */
18 | export const PollsVarPopFieldsModel = PollsVarPopFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsVarSampFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsVarSampFieldsModelBase } from "./PollsVarSampFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsVarSampFieldsModel */
5 | export interface PollsVarSampFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsVarSampFieldsModel */
9 | export {
10 | selectFromPollsVarSampFields,
11 | pollsVarSampFieldsModelPrimitives,
12 | PollsVarSampFieldsModelSelector
13 | } from "./PollsVarSampFieldsModel.base"
14 |
15 | /**
16 | * PollsVarSampFieldsModel
17 | */
18 | export const PollsVarSampFieldsModel = PollsVarSampFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/PollsVarianceFieldsModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { PollsVarianceFieldsModelBase } from "./PollsVarianceFieldsModel.base"
3 |
4 | /* The TypeScript type of an instance of PollsVarianceFieldsModel */
5 | export interface PollsVarianceFieldsModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for PollsVarianceFieldsModel */
9 | export {
10 | selectFromPollsVarianceFields,
11 | pollsVarianceFieldsModelPrimitives,
12 | PollsVarianceFieldsModelSelector
13 | } from "./PollsVarianceFieldsModel.base"
14 |
15 | /**
16 | * PollsVarianceFieldsModel
17 | */
18 | export const PollsVarianceFieldsModel = PollsVarianceFieldsModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/QueryRootModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { QueryRootModelBase } from "./QueryRootModel.base"
3 |
4 | /* The TypeScript type of an instance of QueryRootModel */
5 | export interface QueryRootModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for QueryRootModel */
9 | export {
10 | selectFromQueryRoot,
11 | queryRootModelPrimitives,
12 | QueryRootModelSelector
13 | } from "./QueryRootModel.base"
14 |
15 | /**
16 | * QueryRootModel
17 | */
18 | export const QueryRootModel = QueryRootModelBase.actions((self) => ({
19 | // This is an auto-generated example action.
20 | log() {
21 | console.log(JSON.stringify(self))
22 | }
23 | }))
24 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/RootStore.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { RootStoreBase } from "./RootStore.base"
3 |
4 | export interface RootStoreType extends Instance {}
5 |
6 | export const RootStore = RootStoreBase.actions((self) => ({
7 | // This is an auto-generated example action.
8 | log() {
9 | console.log(JSON.stringify(self))
10 | }
11 | }))
12 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/SubscriptionRootModel.ts:
--------------------------------------------------------------------------------
1 | import { Instance } from "mobx-state-tree"
2 | import { SubscriptionRootModelBase } from "./SubscriptionRootModel.base"
3 |
4 | /* The TypeScript type of an instance of SubscriptionRootModel */
5 | export interface SubscriptionRootModelType
6 | extends Instance {}
7 |
8 | /* A graphql query fragment builders for SubscriptionRootModel */
9 | export {
10 | selectFromSubscriptionRoot,
11 | subscriptionRootModelPrimitives,
12 | SubscriptionRootModelSelector
13 | } from "./SubscriptionRootModel.base"
14 |
15 | /**
16 | * SubscriptionRootModel
17 | */
18 | export const SubscriptionRootModel = SubscriptionRootModelBase.actions(
19 | (self) => ({
20 | // This is an auto-generated example action.
21 | log() {
22 | console.log(JSON.stringify(self))
23 | }
24 | })
25 | )
26 |
--------------------------------------------------------------------------------
/examples/6-scaffolding-ts-hasura/src/models/reactUtils.ts:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | /* tslint:disable */
4 |
5 | import { createStoreContext, createUseQueryHook } from "mst-gql"
6 | import * as React from "react"
7 | import { RootStoreType } from "./RootStore"
8 |
9 | export const StoreContext = createStoreContext(React)
10 |
11 | export const useQuery = createUseQueryHook(StoreContext, React)
12 |
--------------------------------------------------------------------------------
/generator/logger.js:
--------------------------------------------------------------------------------
1 | const c = require("ansi-colors")
2 |
3 | const LOGGER = {
4 | info: (message) => {
5 | console.log(c.green(message))
6 | },
7 | debug: (message) => {
8 | if (!process.env.DEBUG || process.env.DEBUG === "false") return
9 | console.debug(c.blue(message))
10 | },
11 | warning: (message) => {
12 | console.warn(c.yellow(message))
13 | },
14 | error: (message) => {
15 | console.error(c.red(message))
16 | }
17 | }
18 |
19 | module.exports = {
20 | LOGGER
21 | }
22 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | testEnvironment: "node",
3 | testPathIgnorePatterns: ["/node_modules/", "/examples/"],
4 | watchPathIgnorePatterns: [
5 | "/tests/lib/todos/models/",
6 | "/tests/lib/unionTypes/models/"
7 | ],
8 | moduleNameMapper: {
9 | "^mst-gql$": "/src/mst-gql.ts"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/createHttpClient.ts:
--------------------------------------------------------------------------------
1 | import { GraphQLClient } from "graphql-request"
2 |
3 | export type HttpClientOptions = ConstructorParameters[1]
4 |
5 | export function createHttpClient(url: string, options: HttpClientOptions = {}) {
6 | return new GraphQLClient(url, options)
7 | }
8 |
--------------------------------------------------------------------------------
/src/deflateHelper.ts:
--------------------------------------------------------------------------------
1 | export function deflateHelper(store: any, data: any) {
2 | function deflate(data: any): any {
3 | if (!data || typeof data !== "object") return data
4 | if (Array.isArray(data)) return data.map(deflate)
5 |
6 | const { __typename, id } = data
7 |
8 | if (__typename && store.isRootType(__typename)) {
9 | // GQL object with root type, keep only __typename & id
10 | return { __typename, id }
11 | } else {
12 | // GQL object with non-root type, return object with all props deflated
13 | const snapshot: any = {}
14 | for (const key in data) {
15 | snapshot[key] = deflate(data[key])
16 | }
17 | return snapshot
18 | }
19 | }
20 |
21 | return deflate(data)
22 | }
23 |
--------------------------------------------------------------------------------
/src/mst-gql.ts:
--------------------------------------------------------------------------------
1 | export { MSTGQLStore, configureStoreMixin } from "./MSTGQLStore"
2 | export { Query, CaseHandlers, QueryOptions, FetchPolicy } from "./Query"
3 | export { MSTGQLObject, MSTGQLRef, getMSTGQLRefLabelAndId } from "./MSTGQLObject"
4 | export { createHttpClient, HttpClientOptions } from "./createHttpClient"
5 | export { QueryBuilder } from "./queryBuilder"
6 | export * from "./localStorageMixin"
7 | export * from "./react"
8 | export * from "./withTypedRefs"
9 |
--------------------------------------------------------------------------------
/src/utils.ts:
--------------------------------------------------------------------------------
1 | export function getFirstValue(data: any) {
2 | const keys = Object.keys(data)
3 | if (keys.length !== 1)
4 | throw new Error(
5 | `Expected exactly one response key, got: ${keys.join(", ")}`
6 | )
7 | return data[keys[0]]
8 | }
9 |
10 | export function typenameToCollectionName(typename: string) {
11 | return typename.toLowerCase() + "s"
12 | }
13 |
--------------------------------------------------------------------------------
/src/withTypedRefs.ts:
--------------------------------------------------------------------------------
1 | import { IAnyModelType, IModelType } from "mobx-state-tree"
2 |
3 | type Without = Pick>
4 |
5 | type WithRefsModelType = T extends IModelType<
6 | infer P,
7 | infer O,
8 | infer C,
9 | infer S
10 | >
11 | ? IModelType, O & OTHERS, C, S>
12 | : never
13 |
14 | export function withTypedRefs() {
15 | return function (model: T) {
16 | return model as unknown as WithRefsModelType
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/cra-test/.yarnrc.yml:
--------------------------------------------------------------------------------
1 | nodeLinker: node-modules
2 |
--------------------------------------------------------------------------------
/tests/cra-test/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cra-test",
3 | "packageManager": "yarn@3.2.1",
4 | "private": true,
5 | "workspaces": [
6 | "cra-tmp/cra-app"
7 | ],
8 | "dependencies": {
9 | "graphql": "16.5.0",
10 | "graphql-request": "4.3.0",
11 | "graphql-tag": "2.12.6",
12 | "mobx": "6.6.1",
13 | "mobx-react": "7.5.2",
14 | "mobx-state-tree": "5.1.5"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/BookModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * BookBase
11 | * auto generated base class for the model BookModel.
12 | */
13 | export const BookModelBase = ModelBase
14 | .named('Book')
15 | .props({
16 | __typename: types.optional(types.literal("Book"), "Book"),
17 | description: types.union(types.undefined, types.string),
18 | author: types.union(types.undefined, types.string),
19 | })
20 | .views(self => ({
21 | get store() {
22 | return self.__getStore()
23 | }
24 | }))
25 |
26 | export class BookModelSelector extends QueryBuilder {
27 | get description() { return this.__attr(`description`) }
28 | get author() { return this.__attr(`author`) }
29 | }
30 | export function selectFromBook() {
31 | return new BookModelSelector()
32 | }
33 |
34 | export const bookModelPrimitives = selectFromBook().description.author
35 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/BookModel.js:
--------------------------------------------------------------------------------
1 | import { BookModelBase } from "./BookModel.base"
2 |
3 | /* A graphql query fragment builders for BookModel */
4 | export {
5 | selectFromBook,
6 | bookModelPrimitives,
7 | BookModelSelector
8 | } from "./BookModel.base"
9 |
10 | /**
11 | * BookModel
12 | */
13 | export const BookModel = BookModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/ModelBase.js:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/MovieModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * MovieBase
11 | * auto generated base class for the model MovieModel.
12 | */
13 | export const MovieModelBase = ModelBase
14 | .named('Movie')
15 | .props({
16 | __typename: types.optional(types.literal("Movie"), "Movie"),
17 | description: types.union(types.undefined, types.string),
18 | director: types.union(types.undefined, types.string),
19 | })
20 | .views(self => ({
21 | get store() {
22 | return self.__getStore()
23 | }
24 | }))
25 |
26 | export class MovieModelSelector extends QueryBuilder {
27 | get description() { return this.__attr(`description`) }
28 | get director() { return this.__attr(`director`) }
29 | }
30 | export function selectFromMovie() {
31 | return new MovieModelSelector()
32 | }
33 |
34 | export const movieModelPrimitives = selectFromMovie().description.director
35 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/MovieModel.js:
--------------------------------------------------------------------------------
1 | import { MovieModelBase } from "./MovieModel.base"
2 |
3 | /* A graphql query fragment builders for MovieModel */
4 | export {
5 | selectFromMovie,
6 | movieModelPrimitives,
7 | MovieModelSelector
8 | } from "./MovieModel.base"
9 |
10 | /**
11 | * MovieModel
12 | */
13 | export const MovieModel = MovieModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/OrganizationModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * OrganizationBase
11 | * auto generated base class for the model OrganizationModel.
12 | */
13 | export const OrganizationModelBase = ModelBase
14 | .named('Organization')
15 | .props({
16 | __typename: types.optional(types.literal("Organization"), "Organization"),
17 | id: types.identifier,
18 | name: types.union(types.undefined, types.string),
19 | logo: types.union(types.undefined, types.string),
20 | })
21 | .views(self => ({
22 | get store() {
23 | return self.__getStore()
24 | }
25 | }))
26 |
27 | export class OrganizationModelSelector extends QueryBuilder {
28 | get id() { return this.__attr(`id`) }
29 | get name() { return this.__attr(`name`) }
30 | get logo() { return this.__attr(`logo`) }
31 | }
32 | export function selectFromOrganization() {
33 | return new OrganizationModelSelector()
34 | }
35 |
36 | export const organizationModelPrimitives = selectFromOrganization().name.logo
37 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/OrganizationModel.js:
--------------------------------------------------------------------------------
1 | import { OrganizationModelBase } from "./OrganizationModel.base"
2 |
3 | /* A graphql query fragment builders for OrganizationModel */
4 | export {
5 | selectFromOrganization,
6 | organizationModelPrimitives,
7 | OrganizationModelSelector
8 | } from "./OrganizationModel.base"
9 |
10 | /**
11 | * OrganizationModel
12 | */
13 | export const OrganizationModel = OrganizationModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/OwnerModelSelector.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { QueryBuilder } from "mst-gql"
5 | import { OrganizationModelType } from "./OrganizationModel"
6 | import { OrganizationModelSelector } from "./OrganizationModel.base"
7 | import { UserModelType } from "./UserModel"
8 | import { UserModelSelector } from "./UserModel.base"
9 |
10 | export class OwnerModelSelector extends QueryBuilder {
11 | get id() { return this.__attr(`id`) }
12 | get name() { return this.__attr(`name`) }
13 | user(builder) { return this.__inlineFragment(`User`, UserModelSelector, builder) }
14 | organization(builder) { return this.__inlineFragment(`Organization`, OrganizationModelSelector, builder) }
15 | }
16 | export function selectFromOwner() {
17 | return new OwnerModelSelector()
18 | }
19 |
20 | export const ownerModelPrimitives = selectFromOwner().name
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/RepoModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 | import { OrganizationModel } from "./OrganizationModel"
8 | import { OrganizationModelSelector } from "./OrganizationModel.base"
9 | import { OwnerModelSelector } from "./OwnerModelSelector"
10 | import { UserModel } from "./UserModel"
11 | import { UserModelSelector } from "./UserModel.base"
12 |
13 |
14 | /**
15 | * RepoBase
16 | * auto generated base class for the model RepoModel.
17 | */
18 | export const RepoModelBase = ModelBase
19 | .named('Repo')
20 | .props({
21 | __typename: types.optional(types.literal("Repo"), "Repo"),
22 | id: types.identifier,
23 | owner: types.union(types.undefined, types.null, types.union(types.late(() => UserModel), types.late(() => OrganizationModel))),
24 | })
25 | .views(self => ({
26 | get store() {
27 | return self.__getStore()
28 | }
29 | }))
30 |
31 | export class RepoModelSelector extends QueryBuilder {
32 | get id() { return this.__attr(`id`) }
33 | owner(builder) { return this.__child(`owner`, OwnerModelSelector, builder) }
34 | }
35 | export function selectFromRepo() {
36 | return new RepoModelSelector()
37 | }
38 |
39 | export const repoModelPrimitives = selectFromRepo()
40 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/RepoModel.js:
--------------------------------------------------------------------------------
1 | import { RepoModelBase } from "./RepoModel.base"
2 |
3 | /* A graphql query fragment builders for RepoModel */
4 | export {
5 | selectFromRepo,
6 | repoModelPrimitives,
7 | RepoModelSelector
8 | } from "./RepoModel.base"
9 |
10 | /**
11 | * RepoModel
12 | */
13 | export const RepoModel = RepoModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/RootStore.js:
--------------------------------------------------------------------------------
1 | import { RootStoreBase } from "./RootStore.base"
2 |
3 | export const RootStore = RootStoreBase.actions((self) => ({
4 | // This is an auto-generated example action.
5 | log() {
6 | console.log(JSON.stringify(self))
7 | }
8 | }))
9 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/SearchItemModelSelector.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { QueryBuilder } from "mst-gql"
5 | import { BookModelType } from "./BookModel"
6 | import { BookModelSelector, bookModelPrimitives } from "./BookModel.base"
7 | import { MovieModelType } from "./MovieModel"
8 | import { MovieModelSelector, movieModelPrimitives } from "./MovieModel.base"
9 |
10 | export class SearchItemModelSelector extends QueryBuilder {
11 | movie(builder) { return this.__inlineFragment(`Movie`, MovieModelSelector, builder) }
12 | book(builder) { return this.__inlineFragment(`Book`, BookModelSelector, builder) }
13 | }
14 | export function selectFromSearchItem() {
15 | return new SearchItemModelSelector()
16 | }
17 |
18 | // provides all primitive fields of union member types combined together
19 | export const searchItemModelPrimitives = selectFromSearchItem().movie(movieModelPrimitives).book(bookModelPrimitives)
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/SearchResultModel.js:
--------------------------------------------------------------------------------
1 | import { SearchResultModelBase } from "./SearchResultModel.base"
2 |
3 | /* A graphql query fragment builders for SearchResultModel */
4 | export {
5 | selectFromSearchResult,
6 | searchResultModelPrimitives,
7 | SearchResultModelSelector
8 | } from "./SearchResultModel.base"
9 |
10 | /**
11 | * SearchResultModel
12 | */
13 | export const SearchResultModel = SearchResultModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/UserModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * UserBase
11 | * auto generated base class for the model UserModel.
12 | */
13 | export const UserModelBase = ModelBase
14 | .named('User')
15 | .props({
16 | __typename: types.optional(types.literal("User"), "User"),
17 | id: types.identifier,
18 | name: types.union(types.undefined, types.string),
19 | avatar: types.union(types.undefined, types.string),
20 | })
21 | .views(self => ({
22 | get store() {
23 | return self.__getStore()
24 | }
25 | }))
26 |
27 | export class UserModelSelector extends QueryBuilder {
28 | get id() { return this.__attr(`id`) }
29 | get name() { return this.__attr(`name`) }
30 | get avatar() { return this.__attr(`avatar`) }
31 | }
32 | export function selectFromUser() {
33 | return new UserModelSelector()
34 | }
35 |
36 | export const userModelPrimitives = selectFromUser().name.avatar
37 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/UserModel.js:
--------------------------------------------------------------------------------
1 | import { UserModelBase } from "./UserModel.base"
2 |
3 | /* A graphql query fragment builders for UserModel */
4 | export {
5 | selectFromUser,
6 | userModelPrimitives,
7 | UserModelSelector
8 | } from "./UserModel.base"
9 |
10 | /**
11 | * UserModel
12 | */
13 | export const UserModel = UserModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/index.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | export * from "./MovieModel"
5 | export * from "./BookModel"
6 | export * from "./SearchItemModelSelector"
7 | export * from "./SearchResultModel"
8 | export * from "./OwnerModelSelector"
9 | export * from "./UserModel"
10 | export * from "./OrganizationModel"
11 | export * from "./RepoModel"
12 | export * from "./RootStore"
13 | export * from "./reactUtils"
14 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/models/reactUtils.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { createStoreContext, createUseQueryHook } from "mst-gql"
5 | import * as React from "react"
6 |
7 |
8 | export const StoreContext = createStoreContext(React)
9 |
10 | export const useQuery = createUseQueryHook(StoreContext, React)
11 |
--------------------------------------------------------------------------------
/tests/lib/abstractTypes/schema.graphql:
--------------------------------------------------------------------------------
1 | type Query {
2 | search(text: String!): SearchResult!
3 | getAllRepos: [Repo]!
4 | }
5 | type Mutation {
6 | addRepo(name: String!, ownerName: String!, avatar: String, logo: String): Repo
7 | }
8 |
9 | # union types setup
10 | type Movie {
11 | description: String!
12 | director: String!
13 | }
14 | type Book {
15 | description: String!
16 | author: String!
17 | }
18 | union SearchItem = Movie | Book
19 | type SearchResult {
20 | inputQuery: String!
21 | items: [SearchItem]!
22 | }
23 |
24 | # interface types setup
25 | interface Owner {
26 | id: ID!
27 | name: String!
28 | }
29 | type User implements Owner {
30 | id: ID!
31 | name: String!
32 | avatar: String!
33 | }
34 | type Organization implements Owner {
35 | id: ID!
36 | name: String!
37 | logo: String!
38 | }
39 | type Repo {
40 | id: ID!
41 | owner: Owner
42 | }
43 |
--------------------------------------------------------------------------------
/tests/lib/todos/__snapshots__/todostore.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`todos.graphql tests it should be able to instantiate store and load initial data 1`] = `
4 | Object {
5 | "__queryCache": Object {},
6 | "todos": Object {
7 | "a": Object {
8 | "__typename": "Todo",
9 | "complete": false,
10 | "id": "a",
11 | "text": "Initially loaded todo",
12 | },
13 | },
14 | }
15 | `;
16 |
17 | exports[`todos.graphql tests it should be able to instantiate store and load initial data 3`] = `
18 | Object {
19 | "__queryCache": Object {
20 | "query todos { todos {
21 | __typename
22 | id
23 | text
24 | complete
25 |
26 | } }undefined": Object {
27 | "data": Object {
28 | "todos": Array [
29 | Object {
30 | "__typename": "Todo",
31 | "id": "a",
32 | },
33 | Object {
34 | "__typename": "Todo",
35 | "id": "b",
36 | },
37 | ],
38 | },
39 | },
40 | },
41 | "todos": Object {
42 | "a": Object {
43 | "__typename": "Todo",
44 | "complete": true,
45 | "id": "a",
46 | "text": "Initially loaded todo, now updated",
47 | },
48 | "b": Object {
49 | "__typename": "Todo",
50 | "complete": false,
51 | "id": "b",
52 | "text": "Another todo",
53 | },
54 | },
55 | }
56 | `;
57 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/ModelBase.js:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/RootStore.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 | import { types } from "mobx-state-tree"
4 | import { MSTGQLStore, configureStoreMixin } from "mst-gql"
5 |
6 | import { TodoModel } from "./TodoModel"
7 | import { todoModelPrimitives, TodoModelSelector } from "./TodoModel.base"
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | /**
16 | * Store, managing, among others, all the objects received through graphQL
17 | */
18 | export const RootStoreBase = MSTGQLStore
19 | .named("RootStore")
20 | .extend(configureStoreMixin([['Todo', () => TodoModel]], ['Todo'], "js"))
21 | .props({
22 | todos: types.optional(types.map(types.late(() => TodoModel)), {})
23 | })
24 | .actions(self => ({
25 | queryTodos(variables, resultSelector = todoModelPrimitives.toString(), options = {}) {
26 | return self.query(`query todos { todos {
27 | ${typeof resultSelector === "function" ? resultSelector(new TodoModelSelector()).toString() : resultSelector}
28 | } }`, variables, options)
29 | },
30 | mutateToggleTodo(variables, resultSelector = todoModelPrimitives.toString(), optimisticUpdate) {
31 | return self.mutate(`mutation toggleTodo($id: ID!) { toggleTodo(id: $id) {
32 | ${typeof resultSelector === "function" ? resultSelector(new TodoModelSelector()).toString() : resultSelector}
33 | } }`, variables, optimisticUpdate)
34 | },
35 | }))
36 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/RootStore.js:
--------------------------------------------------------------------------------
1 | import { RootStoreBase } from "./RootStore.base"
2 |
3 | export const RootStore = RootStoreBase.actions((self) => ({
4 | // This is an auto-generated example action.
5 | log() {
6 | console.log(JSON.stringify(self))
7 | }
8 | }))
9 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/TodoModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * TodoBase
11 | * auto generated base class for the model TodoModel.
12 | */
13 | export const TodoModelBase = ModelBase
14 | .named('Todo')
15 | .props({
16 | __typename: types.optional(types.literal("Todo"), "Todo"),
17 | id: types.identifier,
18 | text: types.union(types.undefined, types.string),
19 | complete: types.union(types.undefined, types.boolean),
20 | })
21 | .views(self => ({
22 | get store() {
23 | return self.__getStore()
24 | }
25 | }))
26 |
27 | export class TodoModelSelector extends QueryBuilder {
28 | get id() { return this.__attr(`id`) }
29 | get text() { return this.__attr(`text`) }
30 | get complete() { return this.__attr(`complete`) }
31 | }
32 | export function selectFromTodo() {
33 | return new TodoModelSelector()
34 | }
35 |
36 | export const todoModelPrimitives = selectFromTodo().text.complete
37 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/TodoModel.js:
--------------------------------------------------------------------------------
1 | import { TodoModelBase } from "./TodoModel.base"
2 |
3 | /* A graphql query fragment builders for TodoModel */
4 | export {
5 | selectFromTodo,
6 | todoModelPrimitives,
7 | TodoModelSelector
8 | } from "./TodoModel.base"
9 |
10 | /**
11 | * TodoModel
12 | */
13 | export const TodoModel = TodoModelBase.actions((self) => ({
14 | toggle() {
15 | return self.store.mutateToggleTodo({ id: self.id }, (todo) => todo.complete)
16 | }
17 | }))
18 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/index.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | export * from "./TodoModel"
5 | export * from "./RootStore"
6 | export * from "./reactUtils"
7 |
--------------------------------------------------------------------------------
/tests/lib/todos/models/reactUtils.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { createStoreContext, createUseQueryHook } from "mst-gql"
5 | import * as React from "react"
6 |
7 |
8 | export const StoreContext = createStoreContext(React)
9 |
10 | export const useQuery = createUseQueryHook(StoreContext, React)
11 |
--------------------------------------------------------------------------------
/tests/lib/todos/todos.graphql:
--------------------------------------------------------------------------------
1 | type Query {
2 | todos: [Todo]!
3 | }
4 | type Mutation {
5 | toggleTodo(id: ID!): Todo
6 | }
7 | type Todo {
8 | id: ID
9 | text: String!
10 | complete: Boolean!
11 | }
12 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/BasicTodoModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * BasicTodoBase
11 | * auto generated base class for the model BasicTodoModel.
12 | */
13 | export const BasicTodoModelBase = ModelBase
14 | .named('BasicTodo')
15 | .props({
16 | __typename: types.optional(types.literal("BasicTodo"), "BasicTodo"),
17 | id: types.identifier,
18 | text: types.union(types.undefined, types.null, types.string),
19 | complete: types.union(types.undefined, types.null, types.boolean),
20 | })
21 | .views(self => ({
22 | get store() {
23 | return self.__getStore()
24 | }
25 | }))
26 |
27 | export class BasicTodoModelSelector extends QueryBuilder {
28 | get id() { return this.__attr(`id`) }
29 | get text() { return this.__attr(`text`) }
30 | get complete() { return this.__attr(`complete`) }
31 | }
32 | export function selectFromBasicTodo() {
33 | return new BasicTodoModelSelector()
34 | }
35 |
36 | export const basicTodoModelPrimitives = selectFromBasicTodo().text.complete
37 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/BasicTodoModel.js:
--------------------------------------------------------------------------------
1 | import { BasicTodoModelBase } from "./BasicTodoModel.base"
2 |
3 | /* A graphql query fragment builders for BasicTodoModel */
4 | export {
5 | selectFromBasicTodo,
6 | basicTodoModelPrimitives,
7 | BasicTodoModelSelector
8 | } from "./BasicTodoModel.base"
9 |
10 | /**
11 | * BasicTodoModel
12 | */
13 | export const BasicTodoModel = BasicTodoModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/FancyTodoModel.base.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { types } from "mobx-state-tree"
5 | import { QueryBuilder } from "mst-gql"
6 | import { ModelBase } from "./ModelBase"
7 |
8 |
9 | /**
10 | * FancyTodoBase
11 | * auto generated base class for the model FancyTodoModel.
12 | */
13 | export const FancyTodoModelBase = ModelBase
14 | .named('FancyTodo')
15 | .props({
16 | __typename: types.optional(types.literal("FancyTodo"), "FancyTodo"),
17 | id: types.identifier,
18 | label: types.union(types.undefined, types.null, types.string),
19 | color: types.union(types.undefined, types.null, types.string),
20 | complete: types.union(types.undefined, types.null, types.boolean),
21 | })
22 | .views(self => ({
23 | get store() {
24 | return self.__getStore()
25 | }
26 | }))
27 |
28 | export class FancyTodoModelSelector extends QueryBuilder {
29 | get id() { return this.__attr(`id`) }
30 | get label() { return this.__attr(`label`) }
31 | get color() { return this.__attr(`color`) }
32 | get complete() { return this.__attr(`complete`) }
33 | }
34 | export function selectFromFancyTodo() {
35 | return new FancyTodoModelSelector()
36 | }
37 |
38 | export const fancyTodoModelPrimitives = selectFromFancyTodo().label.color.complete
39 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/FancyTodoModel.js:
--------------------------------------------------------------------------------
1 | import { FancyTodoModelBase } from "./FancyTodoModel.base"
2 |
3 | /* A graphql query fragment builders for FancyTodoModel */
4 | export {
5 | selectFromFancyTodo,
6 | fancyTodoModelPrimitives,
7 | FancyTodoModelSelector
8 | } from "./FancyTodoModel.base"
9 |
10 | /**
11 | * FancyTodoModel
12 | */
13 | export const FancyTodoModel = FancyTodoModelBase.actions((self) => ({
14 | // This is an auto-generated example action.
15 | log() {
16 | console.log(JSON.stringify(self))
17 | }
18 | }))
19 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/ModelBase.js:
--------------------------------------------------------------------------------
1 | import { MSTGQLObject } from "mst-gql"
2 |
3 | export const ModelBase = MSTGQLObject
4 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/RootStore.js:
--------------------------------------------------------------------------------
1 | import { RootStoreBase } from "./RootStore.base"
2 |
3 | export const RootStore = RootStoreBase.actions((self) => ({
4 | // This is an auto-generated example action.
5 | log() {
6 | console.log(JSON.stringify(self))
7 | }
8 | }))
9 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/TodoModelSelector.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { QueryBuilder } from "mst-gql"
5 | import { BasicTodoModelType } from "./BasicTodoModel"
6 | import { BasicTodoModelSelector, basicTodoModelPrimitives } from "./BasicTodoModel.base"
7 | import { FancyTodoModelType } from "./FancyTodoModel"
8 | import { FancyTodoModelSelector, fancyTodoModelPrimitives } from "./FancyTodoModel.base"
9 |
10 | export class TodoModelSelector extends QueryBuilder {
11 | basicTodo(builder) { return this.__inlineFragment(`BasicTodo`, BasicTodoModelSelector, builder) }
12 | fancyTodo(builder) { return this.__inlineFragment(`FancyTodo`, FancyTodoModelSelector, builder) }
13 | }
14 | export function selectFromTodo() {
15 | return new TodoModelSelector()
16 | }
17 |
18 | // provides all primitive fields of union member types combined together
19 | export const todoModelPrimitives = selectFromTodo().basicTodo(basicTodoModelPrimitives).fancyTodo(fancyTodoModelPrimitives)
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/index.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | export * from "./TodoModelSelector"
5 | export * from "./BasicTodoModel"
6 | export * from "./FancyTodoModel"
7 | export * from "./TodoListModel"
8 | export * from "./RootStore"
9 | export * from "./reactUtils"
10 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/models/reactUtils.js:
--------------------------------------------------------------------------------
1 | /* This is a mst-gql generated file, don't modify it manually */
2 | /* eslint-disable */
3 |
4 | import { createStoreContext, createUseQueryHook } from "mst-gql"
5 | import * as React from "react"
6 |
7 |
8 | export const StoreContext = createStoreContext(React)
9 |
10 | export const useQuery = createUseQueryHook(StoreContext, React)
11 |
--------------------------------------------------------------------------------
/tests/lib/unionTypes/todos.graphql:
--------------------------------------------------------------------------------
1 | type Query {
2 | todoLists: [TodoList!]!
3 | }
4 |
5 | union Todo = BasicTodo | FancyTodo
6 |
7 | type BasicTodo {
8 | id: ID
9 | text: String
10 | complete: Boolean
11 | }
12 | type FancyTodo {
13 | id: ID
14 | label: String
15 | color: String
16 | complete: Boolean
17 | }
18 | type TodoList {
19 | id: ID!
20 | todos: [Todo!]!
21 | }
22 |
--------------------------------------------------------------------------------