Skip to content

Commit 18cd29a

Browse files
committed
Add preparePersistedQueryList
1 parent 805b6b2 commit 18cd29a

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"format": "apollo-persisted-query-manifest",
3+
"version": 1,
4+
"operations": [
5+
{
6+
"id": "4a29162b05ee4d82ad02e8f50af4bf112f47181ec558a7100a",
7+
"name": "TestQuery1",
8+
"type": "query",
9+
"body": "query TestQuery1 {\n testing {\n id\n label\n description\n __typename\n} }"
10+
},
11+
{
12+
"id": "xyz-123",
13+
"name": "TestQuery2",
14+
"type": "mutation",
15+
"body": "query TestQuery2 {\n testing2 {\n id2\n label\n description2\n __typename\n} }"
16+
}
17+
]
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import preparePersistedQueryList from "../preparePersistedQueryList"
2+
3+
it("reads generate-persisted-query-manifest output", () => {
4+
const manifestPath = "./src/sync/__tests__/generate-persisted-query-manifest.json"
5+
var ops = preparePersistedQueryList(manifestPath)
6+
expect(ops).toMatchSnapshot()
7+
})

javascript_client/src/sync/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface SyncOptions {
1010
relayPersistedOutput?: string,
1111
apolloAndroidOperationOutput?: string,
1212
apolloCodegenJsonOutput?: string,
13+
apolloPersistedQueryManifest?: string,
1314
secret?: string
1415
url?: string,
1516
mode?: string,
@@ -32,6 +33,7 @@ interface SyncOptions {
3233
* @param {String} options.path - A glob to recursively search for `.graphql` files (Default is `./`)
3334
* @param {String} options.relayPersistedOutput - A path to a `.json` file from `relay-compiler`'s `--persist-output` option
3435
* @param {String} options.apolloCodegenJsonOutput - A path to a `.json` file from `apollo client:codegen ... --type json`
36+
* @param {String} options.apolloPersistedQueryManifest - A path to a `.json` file from `generate-persisted-query-manifest`
3537
* @param {String} options.secret - HMAC-SHA256 key which must match the server secret (default is no encryption)
3638
* @param {String} options.url - Target URL for sending prepared queries. If omitted, then an outfile is generated without sending operations to the server.
3739
* @param {String} options.mode - If `"file"`, treat each file separately. If `"project"`, concatenate all files and extract each operation. If `"relay"`, treat it as relay-compiler output
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import fs from "fs"
2+
3+
// Transform the output from generate-persisted-query-manifest
4+
// to something that OperationStore `sync` can use.
5+
export default function preparePersistedQueryList(pqlPath: string) {
6+
const pqlString = fs.readFileSync(pqlPath, "utf8")
7+
const pqlJson = JSON.parse(pqlString)
8+
return pqlJson.operations.map(function(persistedQueryConfig: { body: string, id: string, name: string, type: string }) {
9+
return {
10+
body: persistedQueryConfig.body,
11+
alias: persistedQueryConfig.id,
12+
name: persistedQueryConfig.name
13+
}
14+
})
15+
}

0 commit comments

Comments
 (0)