-
Notifications
You must be signed in to change notification settings - Fork 78
Port Relay test tooling from Reaction, update to Node 10 #1209
Changes from all commits
d695b45
133068b
89c5202
a765905
ab692ae
6df6bf4
eec0d25
31aab9a
72f7553
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8.4 | ||
10.13.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
cache: yarn | ||
language: node_js | ||
node_js: '8.4' | ||
node_js: '10.13.0' | ||
|
||
matrix: | ||
include: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"native-code-version": 9, | ||
"description": "Artsy React(Native) components.", | ||
"engines": { | ||
"node": "8.x.x", | ||
"node": "10.x", | ||
"npm": "6.1.x", | ||
"yarn": "1.x" | ||
}, | ||
|
@@ -30,7 +30,7 @@ | |
"test": "jest", | ||
"test:ci": "jest --outputFile test-results.json --json --runInBand", | ||
"testing": "jest --watch", | ||
"relay": "relay-compiler --src ./src --schema data/schema.graphql --language typescript --artifactDirectory ./src/__generated__ --persist --persistOutput ./src/__generated__/complete.queryMap.json", | ||
"relay": "relay-compiler --src ./src --schema data/schema.graphql --language typescript --artifactDirectory ./src/__generated__ --persist --persistOutput ./src/__generated__/complete.queryMap.json --exclude '**/node_modules/**,**/__mocks__/**,**/__generated__/**'", | ||
"release": "node scripts/release.js", | ||
"generate-graphql-query-map": "node scripts/generate-graphql-query-map.js > Pod/Classes/GraphQL/ARGraphQLQueryMap.generated.objc", | ||
"merge-graphql-query-map": "node scripts/merge-graphql-query-map.js", | ||
|
@@ -61,10 +61,10 @@ | |
"lib" | ||
], | ||
"resolutions": { | ||
"parse5": "5.1.0", | ||
"graphql": "^0.13", | ||
"relay-runtime": "https://github.com/alloy/relay/releases/download/v1.5.0-artsy.5/relay-runtime-1.5.0-artsy.5.tgz", | ||
"@types/relay-runtime": "^1.3.5" | ||
"@types/relay-runtime": "^1.3.5", | ||
"cheerio": "0.22.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My hunch is that enzyme must be passing slightly different configuration options down to cheerio when calling |
||
}, | ||
"dependencies": { | ||
"@artsy/palette": "^2.11.0", | ||
|
@@ -103,7 +103,7 @@ | |
"@types/relay-runtime": "^1.3.5", | ||
"@types/styled-system": "^3.0.1", | ||
"awesome-typescript-loader": "^3.2.3", | ||
"babel-jest": "^22.1.0", | ||
"babel-jest": "^23.6.0", | ||
"babel-plugin-relay": "https://github.com/alloy/relay/releases/download/v1.5.0-artsy.3/babel-plugin-relay-1.5.0-artsy.3.tgz", | ||
"babel-polyfill": "^6.13.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
|
@@ -116,7 +116,7 @@ | |
"enzyme": "^3.1.0", | ||
"enzyme-adapter-react-16": "^1.0.2", | ||
"husky": "^0.14.3", | ||
"jest": "^22.4.2", | ||
"jest": "^23.6.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to upgrade jest as part of upgrading to node 10 due to needing this PR: jestjs/jest#6505 |
||
"jest-styled-components": "^4.10.0", | ||
"lint-staged": "^6.0.0", | ||
"patch-package": "^5.0.0", | ||
|
@@ -130,6 +130,7 @@ | |
"recursive-readdir-sync": "^1.0.6", | ||
"relay-compiler": "https://github.com/alloy/relay/releases/download/v1.5.0-artsy.5/relay-compiler-1.5.0-artsy.5.tgz", | ||
"relay-compiler-language-typescript": "^1.1.0", | ||
"relay-mock-network-layer": "^1.3.0", | ||
"relay2ts": "^0.2.0", | ||
"snapshot-diff": "^0.2.1", | ||
"stylelint": "^8.4.0", | ||
|
@@ -163,6 +164,8 @@ | |
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
}, | ||
"testRegex": "/__tests__/.*-tests.(ts|tsx|js)$", | ||
"testEnvironment": "jsdom", | ||
"testURL": "http://localhost/", | ||
"testPathIgnorePatterns": [ | ||
"\\.snap$", | ||
"<rootDir>/build", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
patch-package | ||
--- a/node_modules/relay-mock-network-layer/index.js | ||
+++ b/node_modules/relay-mock-network-layer/index.js | ||
@@ -1,35 +1,66 @@ | ||
-'use strict'; | ||
+"use strict"; | ||
|
||
-const { makeExecutableSchema, addMockFunctionsToSchema } = require('graphql-tools'); | ||
-const { graphql, printSchema, buildClientSchema } = require('graphql'); | ||
+const { | ||
+ makeExecutableSchema, | ||
+ addMockFunctionsToSchema | ||
+} = require("graphql-tools"); | ||
+const { graphql, printSchema, buildClientSchema } = require("graphql"); | ||
const RelayMockNetworkLayerError = require("./RelayMockNetworkLayerError"); | ||
|
||
-module.exports = function getNetworkLayer({schema, mocks, resolvers}) { | ||
- return function fetchQuery( | ||
- operation, | ||
- variableValues | ||
- ) { | ||
- if (typeof schema === 'object' && schema.data) { | ||
- schema = printSchema(buildClientSchema(schema.data)); | ||
- } | ||
+/** | ||
+ * @param {Object} networkConfig - The configuration for the mock network layer. | ||
+ * @param {(string|Object)} networkConfig.schema - If string, the graphql schema SDL. If object, the JSON introspection query. | ||
+ * @param {Object} networkConfig.mocks - Mock primative resolvers, passed directly to addMockFunctionsToSchema. | ||
+ * @param {Object} networkConfig.resolvers - Default resolvers for a schema. | ||
+ * @param {Object} [networkConfig.resolveQueryFromOperation] - If relay operation query text does not exist, used to resolve the query from the operation. Useful for persisted query support. | ||
+ */ | ||
+function getNetworkLayer({ | ||
+ schema, | ||
+ mocks, | ||
+ resolvers, | ||
+ resolveQueryFromOperation | ||
+}) { | ||
+ return function fetchQuery(operation, variableValues) { | ||
+ if (typeof schema === "object" && schema.data) { | ||
+ schema = printSchema(buildClientSchema(schema.data)); | ||
+ } | ||
|
||
- const executableSchema = makeExecutableSchema({typeDefs: schema, resolvers}); | ||
+ const executableSchema = makeExecutableSchema({ | ||
+ typeDefs: schema, | ||
+ resolvers | ||
+ }); | ||
|
||
- // Add mocks, modifies schema in place | ||
- addMockFunctionsToSchema({ schema: executableSchema, mocks }); | ||
+ // Add mocks, modifies schema in place | ||
+ addMockFunctionsToSchema({ schema: executableSchema, mocks }); | ||
|
||
- return graphql(executableSchema, operation.text, null, null, variableValues).then( | ||
- // Trigger Relay error in case of GraphQL errors (or errors in mutation response) | ||
- // See https://github.com/facebook/relay/issues/1816 | ||
+ const query = | ||
+ operation.text || | ||
+ (resolveQueryFromOperation && resolveQueryFromOperation(operation)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of diff in this file due to running Prettier against it, but this is the only meaningful change. @orta and I paired on adding this in in response to the issue described in the frontend practice meeting. To put it into text: client side query resolving requires access to the relay query operation text which is not immediately available due to Emission's use of persisted queries, where only the ID is in the compiled artifact. This change allows us to pass in a query resolver function, where we then use the same approach used in Our usage of this can be seen here: https://github.com/javamonn/emission/blob/084f721f766476e497ecd078add48c5de5050db8/src/lib/tests/createMockNetworkLayer/index.ts#L21-L23 I will PR these changes against the upstream repository once we land them here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heads up that I have a PR over in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mainly that it increases the difference between dev and prod There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
|
||
- result => { | ||
- if (result.errors && result.errors.length > 0) { | ||
- return Promise.reject(new RelayMockNetworkLayerError(result.errors)); | ||
- } | ||
- return Promise.resolve(result); | ||
- } | ||
- ); | ||
+ if (!query) { | ||
+ throw new Error( | ||
+ "Could not find query, ensure operation.text exists or pass resolveQueryFromOperation." | ||
+ ); | ||
} | ||
-}; | ||
|
||
+ return graphql( | ||
+ executableSchema, | ||
+ query, | ||
+ null, | ||
+ null, | ||
+ variableValues | ||
+ ).then( | ||
+ // Trigger Relay error in case of GraphQL errors (or errors in mutation response) | ||
+ // See https://github.com/facebook/relay/issues/1816 | ||
+ | ||
+ result => { | ||
+ if (result.errors && result.errors.length > 0) { | ||
+ return Promise.reject(new RelayMockNetworkLayerError(result.errors)); | ||
+ } | ||
+ return Promise.resolve(result); | ||
+ } | ||
+ ); | ||
+ }; | ||
+} | ||
|
||
+module.exports = getNetworkLayer; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This resolution does not appear to be necessary anymore. Original discussion here: https://github.com/artsy/emission/pull/1185/files#r217160876