From d9502d58be01503151381672fc9deedd679054f7 Mon Sep 17 00:00:00 2001 From: "Balazs E. Pataki" Date: Mon, 25 Apr 2022 09:50:41 +0200 Subject: [PATCH 1/4] Try upgrading graphql package It seems to work, but need to update tests as well. --- generator/generate.js | 7 ++- package.json | 8 +-- tests/generator/generate.test.js | 1 + .../abstractTypes/models/RootStore.base.js | 10 ++-- tests/lib/abstractTypes/models/index.js | 6 +- tests/lib/unionTypes/models/RootStore.base.js | 6 +- tests/lib/unionTypes/models/index.js | 2 +- yarn.lock | 60 ++++++++++++------- 8 files changed, 62 insertions(+), 38 deletions(-) diff --git a/generator/generate.js b/generator/generate.js index 26887c80..473d91c4 100644 --- a/generator/generate.js +++ b/generator/generate.js @@ -4,6 +4,7 @@ const graphql = require("graphql") const camelcase = require("camelcase") const pluralize = require("pluralize") const escapeStringRegexp = require("escape-string-regexp") +const { getIntrospectionQuery } = require("graphql") const exampleAction = ` .actions(self => ({ // This is an auto-generated example action. @@ -1262,8 +1263,12 @@ function scaffold( fieldOverrides: [] } ) { + const schema = graphql.buildSchema(definition) - const res = graphql.graphqlSync(schema, graphql.introspectionQuery) + //console.log("+++ schema", definition) + // console.log("+++ introspectionQuery", graphql.introspectionQuery, getIntrospectionQuery()) + //const res = graphql.graphqlSync(schema, getIntrospectionQuery()) + const res = graphql.graphqlSync({schema, source: getIntrospectionQuery()}) if (!res.data) throw new Error("graphql parse error:\n\n" + JSON.stringify(res, null, 2)) return generate( diff --git a/package.json b/package.json index b116d538..e1ede158 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mst-gql", - "version": "0.15.0", + "version": "0.15.0-graphql-upgrade", "description": "Bindings for mobx-state-tree and GraphQL", "author": "Michel Weststrate", "keywords": [ @@ -48,8 +48,8 @@ "camelcase": "^6.2.0", "cosmiconfig": "^7.0.0", "fast-json-stable-stringify": "^2.1.0", - "graphql": "14.6.0", - "graphql-request": "^4.0.0", + "graphql": "^16.3.0", + "graphql-request": "^4.2.0", "lodash": "^4.17.21", "pluralize": "^8.0.0", "throttle-debounce": "^3.0.1" @@ -90,6 +90,6 @@ "mobx-state-tree": "^5.0.1" }, "resolutions": { - "graphql": "14.6.0" + "graphql": "^16.3.0" } } diff --git a/tests/generator/generate.test.js b/tests/generator/generate.test.js index 228e4497..7baad169 100644 --- a/tests/generator/generate.test.js +++ b/tests/generator/generate.test.js @@ -176,6 +176,7 @@ type Query { namingConvention: "asis" } ) + console.log("+++ output", output) expect(output).toMatchSnapshot() expect(findFile(output, "SearchItemModelSelector")).toBeTruthy() diff --git a/tests/lib/abstractTypes/models/RootStore.base.js b/tests/lib/abstractTypes/models/RootStore.base.js index 7728ed59..708f143f 100644 --- a/tests/lib/abstractTypes/models/RootStore.base.js +++ b/tests/lib/abstractTypes/models/RootStore.base.js @@ -3,18 +3,18 @@ import { types } from "mobx-state-tree" import { MSTGQLStore, configureStoreMixin } from "mst-gql" -import { SearchResultModel } from "./SearchResultModel" -import { searchResultModelPrimitives, SearchResultModelSelector } from "./SearchResultModel.base" import { MovieModel } from "./MovieModel" import { movieModelPrimitives, MovieModelSelector } from "./MovieModel.base" import { BookModel } from "./BookModel" import { bookModelPrimitives, BookModelSelector } from "./BookModel.base" -import { RepoModel } from "./RepoModel" -import { repoModelPrimitives, RepoModelSelector } from "./RepoModel.base" +import { SearchResultModel } from "./SearchResultModel" +import { searchResultModelPrimitives, SearchResultModelSelector } from "./SearchResultModel.base" import { UserModel } from "./UserModel" import { userModelPrimitives, UserModelSelector } from "./UserModel.base" import { OrganizationModel } from "./OrganizationModel" import { organizationModelPrimitives, OrganizationModelSelector } from "./OrganizationModel.base" +import { RepoModel } from "./RepoModel" +import { repoModelPrimitives, RepoModelSelector } from "./RepoModel.base" import { searchItemModelPrimitives, SearchItemModelSelector } from "./" import { ownerModelPrimitives, OwnerModelSelector } from "./" @@ -29,7 +29,7 @@ import { ownerModelPrimitives, OwnerModelSelector } from "./" */ export const RootStoreBase = MSTGQLStore .named("RootStore") - .extend(configureStoreMixin([['SearchResult', () => SearchResultModel], ['Movie', () => MovieModel], ['Book', () => BookModel], ['Repo', () => RepoModel], ['User', () => UserModel], ['Organization', () => OrganizationModel]], ['SearchResult', 'Repo'])) + .extend(configureStoreMixin([['Movie', () => MovieModel], ['Book', () => BookModel], ['SearchResult', () => SearchResultModel], ['User', () => UserModel], ['Organization', () => OrganizationModel], ['Repo', () => RepoModel]], ['SearchResult', 'Repo'])) .props({ searchresults: types.optional(types.map(types.late(() => SearchResultModel)), {}), repos: types.optional(types.map(types.late(() => RepoModel)), {}) diff --git a/tests/lib/abstractTypes/models/index.js b/tests/lib/abstractTypes/models/index.js index 4c6cee6c..0a42d2c5 100644 --- a/tests/lib/abstractTypes/models/index.js +++ b/tests/lib/abstractTypes/models/index.js @@ -1,13 +1,13 @@ /* This is a mst-gql generated file, don't modify it manually */ /* eslint-disable */ -export * from "./SearchResultModel" -export * from "./SearchItemModelSelector" export * from "./MovieModel" export * from "./BookModel" -export * from "./RepoModel" +export * from "./SearchItemModelSelector" +export * from "./SearchResultModel" export * from "./OwnerModelSelector" export * from "./UserModel" export * from "./OrganizationModel" +export * from "./RepoModel" export * from "./RootStore" export * from "./reactUtils" diff --git a/tests/lib/unionTypes/models/RootStore.base.js b/tests/lib/unionTypes/models/RootStore.base.js index b399bc78..54c9f51a 100644 --- a/tests/lib/unionTypes/models/RootStore.base.js +++ b/tests/lib/unionTypes/models/RootStore.base.js @@ -3,12 +3,12 @@ import { types } from "mobx-state-tree" import { MSTGQLStore, configureStoreMixin } from "mst-gql" -import { TodoListModel } from "./TodoListModel" -import { todoListModelPrimitives, TodoListModelSelector } from "./TodoListModel.base" import { BasicTodoModel } from "./BasicTodoModel" import { basicTodoModelPrimitives, BasicTodoModelSelector } from "./BasicTodoModel.base" import { FancyTodoModel } from "./FancyTodoModel" import { fancyTodoModelPrimitives, FancyTodoModelSelector } from "./FancyTodoModel.base" +import { TodoListModel } from "./TodoListModel" +import { todoListModelPrimitives, TodoListModelSelector } from "./TodoListModel.base" import { todoModelPrimitives, TodoModelSelector } from "./" @@ -22,7 +22,7 @@ import { todoModelPrimitives, TodoModelSelector } from "./" */ export const RootStoreBase = MSTGQLStore .named("RootStore") - .extend(configureStoreMixin([['TodoList', () => TodoListModel], ['BasicTodo', () => BasicTodoModel], ['FancyTodo', () => FancyTodoModel]], ['TodoList', 'BasicTodo', 'FancyTodo'], "js")) + .extend(configureStoreMixin([['BasicTodo', () => BasicTodoModel], ['FancyTodo', () => FancyTodoModel], ['TodoList', () => TodoListModel]], ['TodoList', 'BasicTodo', 'FancyTodo'], "js")) .props({ todoLists: types.optional(types.map(types.late(() => TodoListModel)), {}), basicTodos: types.optional(types.map(types.late(() => BasicTodoModel)), {}), diff --git a/tests/lib/unionTypes/models/index.js b/tests/lib/unionTypes/models/index.js index 7e97f38a..c02f664a 100644 --- a/tests/lib/unionTypes/models/index.js +++ b/tests/lib/unionTypes/models/index.js @@ -1,9 +1,9 @@ /* This is a mst-gql generated file, don't modify it manually */ /* eslint-disable */ -export * from "./TodoListModel" export * from "./TodoModelSelector" export * from "./BasicTodoModel" export * from "./FancyTodoModel" +export * from "./TodoListModel" export * from "./RootStore" export * from "./reactUtils" diff --git a/yarn.lock b/yarn.lock index 46fc9fc6..84202486 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3516,12 +3516,12 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" -cross-fetch@^3.0.6: - version "3.1.4" - resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.4.tgz#9723f3a3a247bf8b89039f3a380a9244e8fa2f39" - integrity sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ== +cross-fetch@^3.1.5: + version "3.1.5" + resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f" + integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw== dependencies: - node-fetch "2.6.1" + node-fetch "2.6.7" cross-spawn@^6.0.5: version "6.0.5" @@ -4579,12 +4579,12 @@ graceful-fs@^4.2.0, graceful-fs@^4.2.4: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== -graphql-request@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-4.0.0.tgz#5e4361d33df1a95ccd7ad23a8ebb6bbca9d5622f" - integrity sha512-cdqQLCXlBGkaLdkLYRl4LtkwaZU6TfpE7/tnUQFl3wXfUPWN74Ov+Q61VuIh+AltS789YfGB6whghmCmeXLvTw== +graphql-request@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-4.2.0.tgz#063377bc2dd29cc46aed3fddcc65fe97b805ba81" + integrity sha512-uFeMyhhl8ss4LFgjlfPeAn2pqYw+CJto+cjj71uaBYIMMK2jPIqgHm5KEFxUk0YDD41A8Bq31a2b4G2WJBlp2Q== dependencies: - cross-fetch "^3.0.6" + cross-fetch "^3.1.5" extract-files "^9.0.0" form-data "^3.0.0" @@ -4607,12 +4607,10 @@ graphql-tag@^2.12.4: dependencies: tslib "^2.1.0" -"graphql@14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0", graphql@14.6.0: - version "14.6.0" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.6.0.tgz#57822297111e874ea12f5cd4419616930cd83e49" - integrity sha512-VKzfvHEKybTKjQVpTFrA5yUq2S9ihcZvfJAtsDBBCuV6wauPu1xl/f9ehgVf0FcEJJs4vz6ysb/ZMkGigQZseg== - dependencies: - iterall "^1.2.2" +"graphql@14.0.2 - 14.2.0 || ^14.3.1 || ^15.0.0", graphql@^16.3.0: + version "16.3.0" + resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.3.0.tgz#a91e24d10babf9e60c706919bb182b53ccdffc05" + integrity sha512-xm+ANmA16BzCT5pLjuXySbQVFwH3oJctUVdy81w1sV0vBU0KgDdBGtxQOUd5zqOBk/JayAFeG8Dlmeq74rjm/A== gzip-size@^3.0.0: version "3.0.0" @@ -5210,7 +5208,7 @@ istanbul-reports@^3.0.2: html-escaper "^2.0.0" istanbul-lib-report "^3.0.0" -iterall@^1.2.1, iterall@^1.2.2: +iterall@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea" integrity sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg== @@ -6373,10 +6371,12 @@ no-case@^3.0.3: lower-case "^2.0.1" tslib "^1.10.0" -node-fetch@2.6.1: - version "2.6.1" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" - integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== +node-fetch@2.6.7: + version "2.6.7" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" + integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== + dependencies: + whatwg-url "^5.0.0" node-fetch@^2.6.1: version "2.6.2" @@ -8285,6 +8285,11 @@ tr46@^2.1.0: dependencies: punycode "^2.1.1" +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= + treeify@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/treeify/-/treeify-1.1.0.tgz#4e31c6a463accd0943879f30667c4fdaff411bb8" @@ -8575,6 +8580,11 @@ walker@^1.0.7: dependencies: makeerror "1.0.x" +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= + webidl-conversions@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff" @@ -8597,6 +8607,14 @@ whatwg-mimetype@^2.3.0: resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf" integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g== +whatwg-url@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= + dependencies: + tr46 "~0.0.3" + webidl-conversions "^3.0.0" + whatwg-url@^8.0.0: version "8.2.2" resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.2.2.tgz#85e7f9795108b53d554cec640b2e8aee2a0d4bfd" From 88c61264a3a12a91b128ce369dbda3ee8e927840 Mon Sep 17 00:00:00 2001 From: "Balazs E. Pataki" Date: Fri, 6 May 2022 16:54:42 +0200 Subject: [PATCH 2/4] Use the new getIntrospectionQuery() Instead of graphql.introspectionQuery we now need to use getIntrospectionQuery() --- generator/mst-gql-scaffold.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/mst-gql-scaffold.js b/generator/mst-gql-scaffold.js index 0031cd53..589a7828 100755 --- a/generator/mst-gql-scaffold.js +++ b/generator/mst-gql-scaffold.js @@ -4,6 +4,7 @@ const path = require("path") const fs = require("fs") const child_process = require("child_process") const graphql = require("graphql") +const { getIntrospectionQuery } = require("graphql") const { getConfig, mergeConfigs } = require("./config") const { generate, writeFiles, logUnexpectedFiles } = require("./generate") @@ -85,7 +86,7 @@ function main() { // Tnx https://blog.apollographql.com/three-ways-to-represent-your-graphql-schema-a41f4175100d! const text = fs.readFileSync(input, "utf8") const schema = graphql.buildSchema(text) - const res = graphql.graphqlSync(schema, graphql.introspectionQuery) + const res = graphql.graphqlSync({schema, source: getIntrospectionQuery()}) if (res.data) json = res.data else { console.error("graphql parse error:\n\n" + JSON.stringify(res, null, 2)) From c22d604349293dea9c3d935bba965d1e7888b39f Mon Sep 17 00:00:00 2001 From: "Balazs E. Pataki" Date: Fri, 6 May 2022 16:55:16 +0200 Subject: [PATCH 3/4] Fix tests --- examples/2-scaffolding/package.json | 2 +- generator/generate.js | 3 - .../__snapshots__/generate.test.js.snap | 496 +++++++++--------- tests/generator/generate.test.js | 2 +- 4 files changed, 250 insertions(+), 253 deletions(-) diff --git a/examples/2-scaffolding/package.json b/examples/2-scaffolding/package.json index 3f9b1adc..5a3b8196 100644 --- a/examples/2-scaffolding/package.json +++ b/examples/2-scaffolding/package.json @@ -18,7 +18,7 @@ "@types/react-dom": "^16.8.4", "react": "^16.8.6", "react-dom": "^16.8.6", - "typescript": "^3.4.5" + "typescript": "^4.6.4" }, "relativeDependencies": { "mst-gql": "../../" diff --git a/generator/generate.js b/generator/generate.js index 3942a128..9a39d68f 100644 --- a/generator/generate.js +++ b/generator/generate.js @@ -1289,9 +1289,6 @@ function scaffold( ) { const schema = graphql.buildSchema(definition) - //console.log("+++ schema", definition) - // console.log("+++ introspectionQuery", graphql.introspectionQuery, getIntrospectionQuery()) - //const res = graphql.graphqlSync(schema, getIntrospectionQuery()) const res = graphql.graphqlSync({schema, source: getIntrospectionQuery()}) if (!res.data) throw new Error("graphql parse error:\n\n" + JSON.stringify(res, null, 2)) diff --git a/tests/generator/__snapshots__/generate.test.js.snap b/tests/generator/__snapshots__/generate.test.js.snap index 28f65079..c2b3b2b1 100644 --- a/tests/generator/__snapshots__/generate.test.js.snap +++ b/tests/generator/__snapshots__/generate.test.js.snap @@ -179,76 +179,6 @@ Array [ "import { MSTGQLObject } from \\"mst-gql\\" export const ModelBase = MSTGQLObject -", - false, - ], - Array [ - "QueryRootModel.base", - "/* This is a mst-gql generated file, don't modify it manually */ -/* eslint-disable */ -/* tslint:disable */ - -import { types } from \\"mobx-state-tree\\" -import { MSTGQLRef, QueryBuilder, withTypedRefs } from \\"mst-gql\\" -import { ModelBase } from \\"./ModelBase\\" -import { MyUserModel, MyUserModelType } from \\"./MyUserModel\\" -import { MyUserModelSelector } from \\"./MyUserModel.base\\" -import { RootStoreType } from \\"./index\\" - - -/* The TypeScript type that explicits the refs to other models in order to prevent a circular refs issue */ -type Refs = { - me: MyUserModelType; -} - -/** - * QueryRootBase - * auto generated base class for the model QueryRootModel. - */ -export const QueryRootModelBase = withTypedRefs()(ModelBase - .named('QueryRoot') - .props({ - __typename: types.optional(types.literal(\\"query_root\\"), \\"query_root\\"), - me: types.union(types.undefined, types.null, MSTGQLRef(types.late((): any => MyUserModel))), - }) - .views(self => ({ - get store() { - return self.__getStore() - } - }))) - -export class QueryRootModelSelector extends QueryBuilder { - me(builder: string | MyUserModelSelector | ((selector: MyUserModelSelector) => MyUserModelSelector) | undefined) { return this.__child(\`me\`, MyUserModelSelector, builder) } -} -export function selectFromQueryRoot() { - return new QueryRootModelSelector() -} - -export const queryRootModelPrimitives = selectFromQueryRoot() -", - true, - ], - Array [ - "QueryRootModel", - "import { Instance } from \\"mobx-state-tree\\" -import { QueryRootModelBase } from \\"./QueryRootModel.base\\" - -/* The TypeScript type of an instance of QueryRootModel */ -export interface QueryRootModelType extends Instance {} - -/* A graphql query fragment builders for QueryRootModel */ -export { selectFromQueryRoot, queryRootModelPrimitives, QueryRootModelSelector } from \\"./QueryRootModel.base\\" - -/** - * QueryRootModel - */ -export const QueryRootModel = QueryRootModelBase - .actions(self => ({ - // This is an auto-generated example action. - log() { - console.log(JSON.stringify(self)) - } - })) ", false, ], @@ -393,6 +323,76 @@ export const PossiblyEmptyBoxModel = PossiblyEmptyBoxModelBase console.log(JSON.stringify(self)) } })) +", + false, + ], + Array [ + "QueryRootModel.base", + "/* This is a mst-gql generated file, don't modify it manually */ +/* eslint-disable */ +/* tslint:disable */ + +import { types } from \\"mobx-state-tree\\" +import { MSTGQLRef, QueryBuilder, withTypedRefs } from \\"mst-gql\\" +import { ModelBase } from \\"./ModelBase\\" +import { MyUserModel, MyUserModelType } from \\"./MyUserModel\\" +import { MyUserModelSelector } from \\"./MyUserModel.base\\" +import { RootStoreType } from \\"./index\\" + + +/* The TypeScript type that explicits the refs to other models in order to prevent a circular refs issue */ +type Refs = { + me: MyUserModelType; +} + +/** + * QueryRootBase + * auto generated base class for the model QueryRootModel. + */ +export const QueryRootModelBase = withTypedRefs()(ModelBase + .named('QueryRoot') + .props({ + __typename: types.optional(types.literal(\\"query_root\\"), \\"query_root\\"), + me: types.union(types.undefined, types.null, MSTGQLRef(types.late((): any => MyUserModel))), + }) + .views(self => ({ + get store() { + return self.__getStore() + } + }))) + +export class QueryRootModelSelector extends QueryBuilder { + me(builder: string | MyUserModelSelector | ((selector: MyUserModelSelector) => MyUserModelSelector) | undefined) { return this.__child(\`me\`, MyUserModelSelector, builder) } +} +export function selectFromQueryRoot() { + return new QueryRootModelSelector() +} + +export const queryRootModelPrimitives = selectFromQueryRoot() +", + true, + ], + Array [ + "QueryRootModel", + "import { Instance } from \\"mobx-state-tree\\" +import { QueryRootModelBase } from \\"./QueryRootModel.base\\" + +/* The TypeScript type of an instance of QueryRootModel */ +export interface QueryRootModelType extends Instance {} + +/* A graphql query fragment builders for QueryRootModel */ +export { selectFromQueryRoot, queryRootModelPrimitives, QueryRootModelSelector } from \\"./QueryRootModel.base\\" + +/** + * QueryRootModel + */ +export const QueryRootModel = QueryRootModelBase + .actions(self => ({ + // This is an auto-generated example action. + log() { + console.log(JSON.stringify(self)) + } + })) ", false, ], @@ -422,12 +422,12 @@ import { ObservableMap } from \\"mobx\\" import { types } from \\"mobx-state-tree\\" import { MSTGQLStore, configureStoreMixin, QueryOptions, withTypedRefs } from \\"mst-gql\\" -import { QueryRootModel, QueryRootModelType } from \\"./QueryRootModel\\" -import { queryRootModelPrimitives, QueryRootModelSelector } from \\"./QueryRootModel.base\\" import { MyUserModel, MyUserModelType } from \\"./MyUserModel\\" import { myUserModelPrimitives, MyUserModelSelector } from \\"./MyUserModel.base\\" import { PossiblyEmptyBoxModel, PossiblyEmptyBoxModelType } from \\"./PossiblyEmptyBoxModel\\" import { possiblyEmptyBoxModelPrimitives, PossiblyEmptyBoxModelSelector } from \\"./PossiblyEmptyBoxModel.base\\" +import { QueryRootModel, QueryRootModelType } from \\"./QueryRootModel\\" +import { queryRootModelPrimitives, QueryRootModelSelector } from \\"./QueryRootModel.base\\" @@ -449,7 +449,7 @@ type Refs = { */ export const RootStoreBase = withTypedRefs()(MSTGQLStore .named(\\"RootStore\\") - .extend(configureStoreMixin([['query_root', () => QueryRootModel], ['my_user', () => MyUserModel], ['possibly_empty_box', () => PossiblyEmptyBoxModel]], ['my_user', 'possibly_empty_box'], \\"js\\")) + .extend(configureStoreMixin([['my_user', () => MyUserModel], ['possibly_empty_box', () => PossiblyEmptyBoxModel], ['query_root', () => QueryRootModel]], ['my_user', 'possibly_empty_box'], \\"js\\")) .props({ myUsers: types.optional(types.map(types.late((): any => MyUserModel)), {}), possiblyEmptyBoxes: types.optional(types.map(types.late((): any => PossiblyEmptyBoxModel)), {}) @@ -486,9 +486,9 @@ export const useQuery = createUseQueryHook(StoreContext, React) /* eslint-disable */ /* tslint:disable */ -export * from \\"./QueryRootModel\\" export * from \\"./MyUserModel\\" export * from \\"./PossiblyEmptyBoxModel\\" +export * from \\"./QueryRootModel\\" export * from \\"./RootStore\\" export * from \\"./reactUtils\\" ", @@ -1157,76 +1157,6 @@ Array [ "import { MSTGQLObject } from \\"mst-gql\\" export const ModelBase = MSTGQLObject -", - false, - ], - Array [ - "RepoModel.base", - "/* This is a mst-gql generated file, don't modify it manually */ -/* eslint-disable */ -/* tslint:disable */ - -import { types } from \\"mobx-state-tree\\" -import { QueryBuilder } from \\"mst-gql\\" -import { ModelBase } from \\"./ModelBase\\" -import { OrganizationModel, OrganizationModelType } from \\"./OrganizationModel\\" -import { OrganizationModelSelector } from \\"./OrganizationModel.base\\" -import { OwnerModelSelector } from \\"./OwnerModelSelector\\" -import { UserModel, UserModelType } from \\"./UserModel\\" -import { UserModelSelector } from \\"./UserModel.base\\" -import { RootStoreType } from \\"./index\\" - - -/** - * RepoBase - * auto generated base class for the model RepoModel. - */ -export const RepoModelBase = ModelBase - .named('Repo') - .props({ - __typename: types.optional(types.literal(\\"Repo\\"), \\"Repo\\"), - id: types.identifier, - owner: types.union(types.undefined, types.null, types.union(types.late((): any => UserModel), types.late((): any => OrganizationModel))), - }) - .views(self => ({ - get store() { - return self.__getStore() - } - })) - -export class RepoModelSelector extends QueryBuilder { - get id() { return this.__attr(\`id\`) } - owner(builder: string | OwnerModelSelector | ((selector: OwnerModelSelector) => OwnerModelSelector) | undefined) { return this.__child(\`owner\`, OwnerModelSelector, builder) } -} -export function selectFromRepo() { - return new RepoModelSelector() -} - -export const repoModelPrimitives = selectFromRepo() -", - true, - ], - Array [ - "RepoModel", - "import { Instance } from \\"mobx-state-tree\\" -import { RepoModelBase } from \\"./RepoModel.base\\" - -/* The TypeScript type of an instance of RepoModel */ -export interface RepoModelType extends Instance {} - -/* A graphql query fragment builders for RepoModel */ -export { selectFromRepo, repoModelPrimitives, RepoModelSelector } from \\"./RepoModel.base\\" - -/** - * RepoModel - */ -export const RepoModel = RepoModelBase - .actions(self => ({ - // This is an auto-generated example action. - log() { - console.log(JSON.stringify(self)) - } - })) ", false, ], @@ -1388,6 +1318,76 @@ export const OrganizationModel = OrganizationModelBase console.log(JSON.stringify(self)) } })) +", + false, + ], + Array [ + "RepoModel.base", + "/* This is a mst-gql generated file, don't modify it manually */ +/* eslint-disable */ +/* tslint:disable */ + +import { types } from \\"mobx-state-tree\\" +import { QueryBuilder } from \\"mst-gql\\" +import { ModelBase } from \\"./ModelBase\\" +import { OrganizationModel, OrganizationModelType } from \\"./OrganizationModel\\" +import { OrganizationModelSelector } from \\"./OrganizationModel.base\\" +import { OwnerModelSelector } from \\"./OwnerModelSelector\\" +import { UserModel, UserModelType } from \\"./UserModel\\" +import { UserModelSelector } from \\"./UserModel.base\\" +import { RootStoreType } from \\"./index\\" + + +/** + * RepoBase + * auto generated base class for the model RepoModel. + */ +export const RepoModelBase = ModelBase + .named('Repo') + .props({ + __typename: types.optional(types.literal(\\"Repo\\"), \\"Repo\\"), + id: types.identifier, + owner: types.union(types.undefined, types.null, types.union(types.late((): any => UserModel), types.late((): any => OrganizationModel))), + }) + .views(self => ({ + get store() { + return self.__getStore() + } + })) + +export class RepoModelSelector extends QueryBuilder { + get id() { return this.__attr(\`id\`) } + owner(builder: string | OwnerModelSelector | ((selector: OwnerModelSelector) => OwnerModelSelector) | undefined) { return this.__child(\`owner\`, OwnerModelSelector, builder) } +} +export function selectFromRepo() { + return new RepoModelSelector() +} + +export const repoModelPrimitives = selectFromRepo() +", + true, + ], + Array [ + "RepoModel", + "import { Instance } from \\"mobx-state-tree\\" +import { RepoModelBase } from \\"./RepoModel.base\\" + +/* The TypeScript type of an instance of RepoModel */ +export interface RepoModelType extends Instance {} + +/* A graphql query fragment builders for RepoModel */ +export { selectFromRepo, repoModelPrimitives, RepoModelSelector } from \\"./RepoModel.base\\" + +/** + * RepoModel + */ +export const RepoModel = RepoModelBase + .actions(self => ({ + // This is an auto-generated example action. + log() { + console.log(JSON.stringify(self)) + } + })) ", false, ], @@ -1417,12 +1417,12 @@ import { ObservableMap } from \\"mobx\\" import { types } from \\"mobx-state-tree\\" import { MSTGQLStore, configureStoreMixin, QueryOptions, withTypedRefs } from \\"mst-gql\\" -import { RepoModel, RepoModelType } from \\"./RepoModel\\" -import { repoModelPrimitives, RepoModelSelector } from \\"./RepoModel.base\\" import { UserModel, UserModelType } from \\"./UserModel\\" import { userModelPrimitives, UserModelSelector } from \\"./UserModel.base\\" import { OrganizationModel, OrganizationModelType } from \\"./OrganizationModel\\" import { organizationModelPrimitives, OrganizationModelSelector } from \\"./OrganizationModel.base\\" +import { RepoModel, RepoModelType } from \\"./RepoModel\\" +import { repoModelPrimitives, RepoModelSelector } from \\"./RepoModel.base\\" import { ownerModelPrimitives, OwnerModelSelector , OwnerUnion } from \\"./\\" @@ -1446,7 +1446,7 @@ queryRepo=\\"queryRepo\\" */ export const RootStoreBase = withTypedRefs()(MSTGQLStore .named(\\"RootStore\\") - .extend(configureStoreMixin([['Repo', () => RepoModel], ['User', () => UserModel], ['Organization', () => OrganizationModel]], ['Repo'])) + .extend(configureStoreMixin([['User', () => UserModel], ['Organization', () => OrganizationModel], ['Repo', () => RepoModel]], ['Repo'])) .props({ repos: types.optional(types.map(types.late((): any => RepoModel)), {}) }) @@ -1482,10 +1482,10 @@ export const useQuery = createUseQueryHook(StoreContext, React) /* eslint-disable */ /* tslint:disable */ -export * from \\"./RepoModel\\" export * from \\"./OwnerModelSelector\\" export * from \\"./UserModel\\" export * from \\"./OrganizationModel\\" +export * from \\"./RepoModel\\" export * from \\"./RootStore\\" export * from \\"./reactUtils\\" ", @@ -2826,7 +2826,7 @@ export const ModelBase = MSTGQLObject false, ], Array [ - "SearchResultModel.base", + "MovieModel.base", "/* This is a mst-gql generated file, don't modify it manually */ /* eslint-disable */ /* tslint:disable */ @@ -2834,24 +2834,19 @@ export const ModelBase = MSTGQLObject import { types } from \\"mobx-state-tree\\" import { QueryBuilder } from \\"mst-gql\\" import { ModelBase } from \\"./ModelBase\\" -import { BookModel, BookModelType } from \\"./BookModel\\" -import { BookModelSelector } from \\"./BookModel.base\\" -import { MovieModel, MovieModelType } from \\"./MovieModel\\" -import { MovieModelSelector } from \\"./MovieModel.base\\" -import { SearchItemModelSelector } from \\"./SearchItemModelSelector\\" import { RootStoreType } from \\"./index\\" /** - * SearchResultBase - * auto generated base class for the model SearchResultModel. + * MovieBase + * auto generated base class for the model MovieModel. */ -export const SearchResultModelBase = ModelBase - .named('SearchResult') +export const MovieModelBase = ModelBase + .named('Movie') .props({ - __typename: types.optional(types.literal(\\"SearchResult\\"), \\"SearchResult\\"), - inputQuery: types.union(types.undefined, types.string), - items: types.union(types.undefined, types.array(types.union(types.null, types.union(types.late((): any => MovieModel), types.late((): any => BookModel))))), + __typename: types.optional(types.literal(\\"Movie\\"), \\"Movie\\"), + description: types.union(types.undefined, types.string), + director: types.union(types.undefined, types.string), }) .views(self => ({ get store() { @@ -2859,33 +2854,33 @@ export const SearchResultModelBase = ModelBase } })) -export class SearchResultModelSelector extends QueryBuilder { - get inputQuery() { return this.__attr(\`inputQuery\`) } - items(builder: string | SearchItemModelSelector | ((selector: SearchItemModelSelector) => SearchItemModelSelector) | undefined) { return this.__child(\`items\`, SearchItemModelSelector, builder) } +export class MovieModelSelector extends QueryBuilder { + get description() { return this.__attr(\`description\`) } + get director() { return this.__attr(\`director\`) } } -export function selectFromSearchResult() { - return new SearchResultModelSelector() +export function selectFromMovie() { + return new MovieModelSelector() } -export const searchResultModelPrimitives = selectFromSearchResult().inputQuery +export const movieModelPrimitives = selectFromMovie().description.director ", true, ], Array [ - "SearchResultModel", + "MovieModel", "import { Instance } from \\"mobx-state-tree\\" -import { SearchResultModelBase } from \\"./SearchResultModel.base\\" +import { MovieModelBase } from \\"./MovieModel.base\\" -/* The TypeScript type of an instance of SearchResultModel */ -export interface SearchResultModelType extends Instance {} +/* The TypeScript type of an instance of MovieModel */ +export interface MovieModelType extends Instance {} -/* A graphql query fragment builders for SearchResultModel */ -export { selectFromSearchResult, searchResultModelPrimitives, SearchResultModelSelector } from \\"./SearchResultModel.base\\" +/* A graphql query fragment builders for MovieModel */ +export { selectFromMovie, movieModelPrimitives, MovieModelSelector } from \\"./MovieModel.base\\" /** - * SearchResultModel + * MovieModel */ -export const SearchResultModel = SearchResultModelBase +export const MovieModel = MovieModelBase .actions(self => ({ // This is an auto-generated example action. log() { @@ -2896,33 +2891,7 @@ export const SearchResultModel = SearchResultModelBase false, ], Array [ - "SearchItemModelSelector", - "/* This is a mst-gql generated file, don't modify it manually */ -/* eslint-disable */ -/* tslint:disable */ - -import { QueryBuilder } from \\"mst-gql\\" -import { BookModelType } from \\"./BookModel\\" -import { BookModelSelector, bookModelPrimitives } from \\"./BookModel.base\\" -import { MovieModelType } from \\"./MovieModel\\" -import { MovieModelSelector, movieModelPrimitives } from \\"./MovieModel.base\\" - -export type SearchItemUnion = MovieModelType | BookModelType - -export class SearchItemModelSelector extends QueryBuilder { - movie(builder?: string | MovieModelSelector | ((selector: MovieModelSelector) => MovieModelSelector)) { return this.__inlineFragment(\`Movie\`, MovieModelSelector, builder) } - book(builder?: string | BookModelSelector | ((selector: BookModelSelector) => BookModelSelector)) { return this.__inlineFragment(\`Book\`, BookModelSelector, builder) } -} -export function selectFromSearchItem() { - return new SearchItemModelSelector() -} - -// provides all primitive fields of union member types combined together -export const searchItemModelPrimitives = selectFromSearchItem().movie(movieModelPrimitives).book(bookModelPrimitives)", - true, - ], - Array [ - "MovieModel.base", + "BookModel.base", "/* This is a mst-gql generated file, don't modify it manually */ /* eslint-disable */ /* tslint:disable */ @@ -2934,15 +2903,15 @@ import { RootStoreType } from \\"./index\\" /** - * MovieBase - * auto generated base class for the model MovieModel. + * BookBase + * auto generated base class for the model BookModel. */ -export const MovieModelBase = ModelBase - .named('Movie') +export const BookModelBase = ModelBase + .named('Book') .props({ - __typename: types.optional(types.literal(\\"Movie\\"), \\"Movie\\"), + __typename: types.optional(types.literal(\\"Book\\"), \\"Book\\"), description: types.union(types.undefined, types.string), - director: types.union(types.undefined, types.string), + author: types.union(types.undefined, types.string), }) .views(self => ({ get store() { @@ -2950,33 +2919,33 @@ export const MovieModelBase = ModelBase } })) -export class MovieModelSelector extends QueryBuilder { +export class BookModelSelector extends QueryBuilder { get description() { return this.__attr(\`description\`) } - get director() { return this.__attr(\`director\`) } + get author() { return this.__attr(\`author\`) } } -export function selectFromMovie() { - return new MovieModelSelector() +export function selectFromBook() { + return new BookModelSelector() } -export const movieModelPrimitives = selectFromMovie().description.director +export const bookModelPrimitives = selectFromBook().description.author ", true, ], Array [ - "MovieModel", + "BookModel", "import { Instance } from \\"mobx-state-tree\\" -import { MovieModelBase } from \\"./MovieModel.base\\" +import { BookModelBase } from \\"./BookModel.base\\" -/* The TypeScript type of an instance of MovieModel */ -export interface MovieModelType extends Instance {} +/* The TypeScript type of an instance of BookModel */ +export interface BookModelType extends Instance {} -/* A graphql query fragment builders for MovieModel */ -export { selectFromMovie, movieModelPrimitives, MovieModelSelector } from \\"./MovieModel.base\\" +/* A graphql query fragment builders for BookModel */ +export { selectFromBook, bookModelPrimitives, BookModelSelector } from \\"./BookModel.base\\" /** - * MovieModel + * BookModel */ -export const MovieModel = MovieModelBase +export const BookModel = BookModelBase .actions(self => ({ // This is an auto-generated example action. log() { @@ -2987,7 +2956,33 @@ export const MovieModel = MovieModelBase false, ], Array [ - "BookModel.base", + "SearchItemModelSelector", + "/* This is a mst-gql generated file, don't modify it manually */ +/* eslint-disable */ +/* tslint:disable */ + +import { QueryBuilder } from \\"mst-gql\\" +import { BookModelType } from \\"./BookModel\\" +import { BookModelSelector, bookModelPrimitives } from \\"./BookModel.base\\" +import { MovieModelType } from \\"./MovieModel\\" +import { MovieModelSelector, movieModelPrimitives } from \\"./MovieModel.base\\" + +export type SearchItemUnion = MovieModelType | BookModelType + +export class SearchItemModelSelector extends QueryBuilder { + movie(builder?: string | MovieModelSelector | ((selector: MovieModelSelector) => MovieModelSelector)) { return this.__inlineFragment(\`Movie\`, MovieModelSelector, builder) } + book(builder?: string | BookModelSelector | ((selector: BookModelSelector) => BookModelSelector)) { return this.__inlineFragment(\`Book\`, BookModelSelector, builder) } +} +export function selectFromSearchItem() { + return new SearchItemModelSelector() +} + +// provides all primitive fields of union member types combined together +export const searchItemModelPrimitives = selectFromSearchItem().movie(movieModelPrimitives).book(bookModelPrimitives)", + true, + ], + Array [ + "SearchResultModel.base", "/* This is a mst-gql generated file, don't modify it manually */ /* eslint-disable */ /* tslint:disable */ @@ -2995,19 +2990,24 @@ export const MovieModel = MovieModelBase import { types } from \\"mobx-state-tree\\" import { QueryBuilder } from \\"mst-gql\\" import { ModelBase } from \\"./ModelBase\\" +import { BookModel, BookModelType } from \\"./BookModel\\" +import { BookModelSelector } from \\"./BookModel.base\\" +import { MovieModel, MovieModelType } from \\"./MovieModel\\" +import { MovieModelSelector } from \\"./MovieModel.base\\" +import { SearchItemModelSelector } from \\"./SearchItemModelSelector\\" import { RootStoreType } from \\"./index\\" /** - * BookBase - * auto generated base class for the model BookModel. + * SearchResultBase + * auto generated base class for the model SearchResultModel. */ -export const BookModelBase = ModelBase - .named('Book') +export const SearchResultModelBase = ModelBase + .named('SearchResult') .props({ - __typename: types.optional(types.literal(\\"Book\\"), \\"Book\\"), - description: types.union(types.undefined, types.string), - author: types.union(types.undefined, types.string), + __typename: types.optional(types.literal(\\"SearchResult\\"), \\"SearchResult\\"), + inputQuery: types.union(types.undefined, types.string), + items: types.union(types.undefined, types.array(types.union(types.null, types.union(types.late((): any => MovieModel), types.late((): any => BookModel))))), }) .views(self => ({ get store() { @@ -3015,33 +3015,33 @@ export const BookModelBase = ModelBase } })) -export class BookModelSelector extends QueryBuilder { - get description() { return this.__attr(\`description\`) } - get author() { return this.__attr(\`author\`) } +export class SearchResultModelSelector extends QueryBuilder { + get inputQuery() { return this.__attr(\`inputQuery\`) } + items(builder: string | SearchItemModelSelector | ((selector: SearchItemModelSelector) => SearchItemModelSelector) | undefined) { return this.__child(\`items\`, SearchItemModelSelector, builder) } } -export function selectFromBook() { - return new BookModelSelector() +export function selectFromSearchResult() { + return new SearchResultModelSelector() } -export const bookModelPrimitives = selectFromBook().description.author +export const searchResultModelPrimitives = selectFromSearchResult().inputQuery ", true, ], Array [ - "BookModel", + "SearchResultModel", "import { Instance } from \\"mobx-state-tree\\" -import { BookModelBase } from \\"./BookModel.base\\" +import { SearchResultModelBase } from \\"./SearchResultModel.base\\" -/* The TypeScript type of an instance of BookModel */ -export interface BookModelType extends Instance {} +/* The TypeScript type of an instance of SearchResultModel */ +export interface SearchResultModelType extends Instance {} -/* A graphql query fragment builders for BookModel */ -export { selectFromBook, bookModelPrimitives, BookModelSelector } from \\"./BookModel.base\\" +/* A graphql query fragment builders for SearchResultModel */ +export { selectFromSearchResult, searchResultModelPrimitives, SearchResultModelSelector } from \\"./SearchResultModel.base\\" /** - * BookModel + * SearchResultModel */ -export const BookModel = BookModelBase +export const SearchResultModel = SearchResultModelBase .actions(self => ({ // This is an auto-generated example action. log() { @@ -3077,12 +3077,12 @@ import { ObservableMap } from \\"mobx\\" import { types } from \\"mobx-state-tree\\" import { MSTGQLStore, configureStoreMixin, QueryOptions, withTypedRefs } from \\"mst-gql\\" -import { SearchResultModel, SearchResultModelType } from \\"./SearchResultModel\\" -import { searchResultModelPrimitives, SearchResultModelSelector } from \\"./SearchResultModel.base\\" import { MovieModel, MovieModelType } from \\"./MovieModel\\" import { movieModelPrimitives, MovieModelSelector } from \\"./MovieModel.base\\" import { BookModel, BookModelType } from \\"./BookModel\\" import { bookModelPrimitives, BookModelSelector } from \\"./BookModel.base\\" +import { SearchResultModel, SearchResultModelType } from \\"./SearchResultModel\\" +import { searchResultModelPrimitives, SearchResultModelSelector } from \\"./SearchResultModel.base\\" import { searchItemModelPrimitives, SearchItemModelSelector , SearchItemUnion } from \\"./\\" @@ -3106,7 +3106,7 @@ querySearch=\\"querySearch\\" */ export const RootStoreBase = withTypedRefs()(MSTGQLStore .named(\\"RootStore\\") - .extend(configureStoreMixin([['SearchResult', () => SearchResultModel], ['Movie', () => MovieModel], ['Book', () => BookModel]], ['SearchResult'])) + .extend(configureStoreMixin([['Movie', () => MovieModel], ['Book', () => BookModel], ['SearchResult', () => SearchResultModel]], ['SearchResult'])) .props({ searchresults: types.optional(types.map(types.late((): any => SearchResultModel)), {}) }) @@ -3142,10 +3142,10 @@ export const useQuery = createUseQueryHook(StoreContext, React) /* eslint-disable */ /* tslint:disable */ -export * from \\"./SearchResultModel\\" -export * from \\"./SearchItemModelSelector\\" export * from \\"./MovieModel\\" export * from \\"./BookModel\\" +export * from \\"./SearchItemModelSelector\\" +export * from \\"./SearchResultModel\\" export * from \\"./RootStore\\" export * from \\"./reactUtils\\" ", diff --git a/tests/generator/generate.test.js b/tests/generator/generate.test.js index 7baad169..4e933213 100644 --- a/tests/generator/generate.test.js +++ b/tests/generator/generate.test.js @@ -102,7 +102,7 @@ type query_root { expect( hasFileContent( findFile(output, "RootStore.base"), - `.extend(configureStoreMixin([['query_root', () => QueryRootModel], ['my_user', () => MyUserModel], ['possibly_empty_box', () => PossiblyEmptyBoxModel]], ['my_user', 'possibly_empty_box'], "js"))` + `.extend(configureStoreMixin([['my_user', () => MyUserModel], ['possibly_empty_box', () => PossiblyEmptyBoxModel], ['query_root', () => QueryRootModel]], ['my_user', 'possibly_empty_box'], "js"))` ) ).toBeTruthy() }) From d50dc5702738a4682ad1836b6be3cf77200442ec Mon Sep 17 00:00:00 2001 From: "Balazs E. Pataki" Date: Fri, 6 May 2022 20:17:53 +0200 Subject: [PATCH 4/4] Add test-cra.sh It can be used to test mst-gql in a new CRA app with all new dependencies. Run when "yarn test" is called. --- package.json | 4 +-- tests/test-cra.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 tests/test-cra.sh diff --git a/package.json b/package.json index 1dd7043c..d725d901 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mst-gql", - "version": "0.15.0-graphql-upgrade", + "version": "0.15.0-361-graphql-upgrade", "description": "Bindings for mobx-state-tree and GraphQL", "author": "Michel Weststrate", "keywords": [ @@ -31,7 +31,7 @@ "generator" ], "scripts": { - "test": "jest test && cd examples/2-scaffolding && yarn && yarn start && cd ../6-scaffolding-ts-hasura && yarn && yarn start ", + "test": "jest test && cd examples/2-scaffolding && yarn && yarn start && cd ../6-scaffolding-ts-hasura && yarn && yarn start && cd ../../tests && ./test-cra.sh && rm -rf cra-test", "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand", "watch": "jest test --watch", "build": "microbundle --no-compress --external mobx,mobx-react,mobx-state-tree,graphql-tag,graphql,react,react-dom,graphql-request", diff --git a/tests/test-cra.sh b/tests/test-cra.sh new file mode 100755 index 00000000..88588cce --- /dev/null +++ b/tests/test-cra.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +# Creates a new CRA app with the latest version of mst-gql dependencies added to it. An mst model is generated using +# the graphql schema copied from examples/6-scaffolding-ts-hasura/schema.graphql and then the app is run to +# see if it can run all right. +# +# +# Note: the generated cra-test directory should not be checked into git. Unfortunately it cannot be added to .gitignore +# otherwise relative-deps won't work (it ignores files in .gitignore). +# + +rm -rf cra-test + +mkdir cra-test +cd cra-test + +npx create-react-app cra-app --template typescript +cd cra-app +cp ../../../examples/6-scaffolding-ts-hasura/schema.graphql . +yarn add mobx mobx-state-tree mobx-react react react-dom mst-gql graphql-request +yarn add graphql graphql-tag +yarn add relative-deps + +# Add current ms-gql version as relative dependency +# perl -0777 -pi.original -e 's|\}$|},\n "relativeDependencies": {\n "mst-gql": "../../../"\n }|sm' package.json +npx relative-deps add ../../../ + +# Load mst-gql relative deps +node_modules/.bin/relative-deps + +# Add some code to import the generated files +perl -0777 -pi.original -e 's|(import.*?./App.css.*?;)|\1\nimport {RootStore} from "./model/RootStore";\nconst rootStore = RootStore.create({})|sm' src/App.tsx + +# now generate models +npx mst-gql --format ts --outDir src/model schema.graphql +# Compile it +npx tsc --extendedDiagnostics + +# run the project and check if runs all right. Not sure how portable or exact this is, but seems to work +rm -f out +yarn start | tee ./out 2>&1 & + +echo -n "Checking if app runs all right " +for i in {1..20} +do + # Failed to compile. + failed=`egrep 'Failed to compile|ERROR in' out` + if [[ ! -z ${failed} ]]; then + echo + echo "App failed to compile" + pid=`ps -ef | grep tests/cra-test/cra-app | grep -v grep | awk '{print $2}' -` + kill -9 $pid > /dev/null 2>&1 + exit + fi + + no_issues=`grep 'No issues found.' out | wc -l` + if [ "$no_issues" -eq "1" ]; then + echo + echo "App ran successfully!" + pid=`ps -ef | grep tests/cra-test/cra-app | grep -v grep | awk '{print $2}' -` + kill -9 $pid > /dev/null 2>&1 + exit + fi + + echo -n "." + + sleep 3 +done +