Skip to content

Commit 5fcb813

Browse files
authored
Merge pull request #59 from firstlookmedia/fix-pq-env-stuff
edit persisted queries checks
2 parents aa2d709 + bd98a9d commit 5fcb813

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "all",
3+
"singleQuote": true,
4+
"printWidth": 90
5+
}

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ To install on OSX `brew bundle` in this directory.
5959

6060
## Persisted queries
6161

62-
By default, sites will not persist static queries. To enable persisted queries:
62+
To enable persisted queries:
6363

64-
1. add `PERSIST_QUERIES: "true"` to all build circle configs
65-
2. add `QUERIES_S3_BUCKET` property to all build and deploy circle configs and point it to the s3 bucket where the site's queries live
66-
3. upgrade to the newest version of React scripts that has the `get` and `post` fetcher methods
67-
4. install our forked version of relay compiler: https://github.com/firstlookmedia/relay contains the .tar.gz of the compiler and you refer to it like so in the `package.json`: https://github.com/firstlookmedia/relay/releases/download/v1.5.0-flm.1/relay-compiler-1.5.0-flm.1.tar.gz
64+
1. Add `PERSIST_QUERIES: "true"` in the build and runtime environments
65+
2. Point `QUERIES_S3_BUCKET` to an s3 bucket during build time to deploy queries, making them accessible to the graphql backend
66+
3. Upgrade to the newest version of React scripts that has the `GET` and `POST` fetcher methods
67+
4. Upgrade to relay >= 3.0
6868

6969
Note: persisted queries are always turned off during local development.
70-
71-
### relay compiler
72-
73-
We are using a forked version of relay similar to what the artsy folks are doing. Hopefully, this fork will get merged into relay proper, at which point we won't need to do anything special to get persisted static queries to work. Until then, we will need to stick to relay version `1.5.0` and if we do need to upgrade we'll have to update our fork, rebuild the compiler, and release it. The artsy folks and others have done an excellent job of keeping this fork up to date with subsequent relay releases, so this should not pose much a problem. In fact, it would be great for us to help with merging upstream relay releases into the PR version on the relay repository if necessary.
74-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firstlookmedia/react-scripts",
3-
"version": "2.0.0-rc6",
3+
"version": "2.0.0-rc10",
44
"description": "shared react site configs",
55
"author": "First Look Media",
66
"license": "MIT",

scripts/build.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
process.env.NODE_ENV = 'production';
32

43
const webpack = require('webpack');
@@ -70,7 +69,7 @@ relayCompiler.on('close', (code) => {
7069
console.log();
7170
console.log('Building server files...');
7271
webpack(serverConfig).run(handler.bind(null, serverConfig));
73-
if (process.env.PERSIST_QUERIES) {
72+
if (process.env.PERSIST_QUERIES === 'true') {
7473
buildPersistedQueries();
7574
}
7675
});

scripts/upload-queries.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const mime = require('mime');
77

88
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });
99
const queriesBucket = process.env.QUERIES_S3_BUCKET;
10+
const persist = process.env.PERSIST_QUERIES === 'true';
1011
const uploadParams = {
1112
Bucket: queriesBucket,
1213
Key: '',
@@ -17,12 +18,19 @@ const uploadParams = {
1718
};
1819
const baseDir = './build/queries';
1920

21+
if (!persist) {
22+
console.error('Persist queries turned off. Exiting.');
23+
process.exit(0);
24+
}
25+
2026
if (!queriesBucket) {
2127
console.error('QUERIES_S3_BUCKET is empty. Exiting.');
2228
process.exit(1);
2329
}
2430

2531
fs.readdir(baseDir, (err, files) => {
32+
if (!files || files.length < 1) return;
33+
2634
files.forEach((file) => {
2735
const fileStream = fs.createReadStream(path.join(baseDir, file));
2836
fileStream.on('error', (err) => {

scripts/utils/relayCompilerArguments.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ module.exports = [
3434
'src/__generated__',
3535

3636
// FIXME: relay fork persist queries flag, remove when no projects use the fork
37-
process.env.PERSIST_QUERIES ? '--persist' : '',
37+
process.env.PERSIST_QUERIES === 'true' ? '--persist' : '',
3838

3939
// relay v2+ persist queries flag
40-
process.env.PERSIST_QUERIES ? '--persist-output' : '',
41-
process.env.PERSIST_QUERIES ? './complete.queryMap.json' : '',
40+
process.env.PERSIST_QUERIES === 'true' ? '--persist-output' : '',
41+
process.env.PERSIST_QUERIES === 'true' ? './complete.queryMap.json' : '',
4242
].reduce((acc, item) => acc.concat(item), []);

template/src/fetcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class FetcherBase {
4646

4747
export class ServerFetcher extends FetcherBase {
4848
constructor(url) {
49-
const isStaticQueries = process.env.PERSIST_QUERIES;
49+
const isStaticQueries = process.env.PERSIST_QUERIES === 'true';
5050
super(url, isStaticQueries);
5151

5252
this.payloads = [];
@@ -67,7 +67,7 @@ export class ServerFetcher extends FetcherBase {
6767

6868
export class ClientFetcher extends FetcherBase {
6969
constructor(url, payloads) {
70-
const isStaticQueries = envConfig.PERSIST_QUERIES;
70+
const isStaticQueries = envConfig.PERSIST_QUERIES === 'true';
7171
super(url, isStaticQueries);
7272

7373
this.payloads = payloads;

0 commit comments

Comments
 (0)