This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from bookmoons/bookmoons/graphql-var
Support GraphQL variables
- Loading branch information
Showing
9 changed files
with
234 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
bin/libs | ||
bin/*.json | ||
npm-debug.log | ||
package-lock.json | ||
.bundle | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "068355d1-ef5d-446c-9cf3-97823da6a196", | ||
"name": "GitHub GraphQL", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Query", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"id": "186b3734-3fe3-4495-b4c9-44b0245dbe3c", | ||
"exec": [ | ||
"console.log(pm.response.text())" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"auth": { | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "token", | ||
"value": "{{GITHUB_TOKEN}}", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "graphql", | ||
"graphql": { | ||
"query": "{\n viewer {\n name\n repositories(last: {{numberOfRepos}}) {\n nodes {\n name\n }\n }\n }\n}\n", | ||
"variables": "" | ||
} | ||
}, | ||
"url": { | ||
"raw": "https://api.github.com/graphql", | ||
"protocol": "https", | ||
"host": [ | ||
"api", | ||
"github", | ||
"com" | ||
], | ||
"path": [ | ||
"graphql" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
], | ||
"variable": [ | ||
{ | ||
"id": "b414bfbd-b39b-460a-bbe4-3e768b3784a0", | ||
"key": "numberOfRepos", | ||
"value": "3", | ||
"type": "string" | ||
}, | ||
{ | ||
"id": "9dff4a0c-28c0-44ff-aebf-1439fd9298a5", | ||
"key": "GITHUB_TOKEN", | ||
"value": "", | ||
"type": "string" | ||
} | ||
] | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import test from 'ava' | ||
import convertFile from 'convert/file' | ||
|
||
function render (body) { | ||
const content = JSON.stringify(body) | ||
const escaped = content.replace(/\\/g, '\\\\') | ||
return `'${escaped}'` | ||
} | ||
|
||
test('body simple', async t => { | ||
const [ main ] = await convertFile( | ||
'test/material/2.1/graphql-body-simple.json' | ||
) | ||
const query = '' + | ||
`{ | ||
user { | ||
name | ||
} | ||
}` | ||
const body = { query } | ||
t.is(main, `// Auto-generated by the Load Impact converter | ||
import "./libs/shim/core.js"; | ||
export let options = { maxRedirects: 4 }; | ||
const Request = Symbol.for("request"); | ||
postman[Symbol.for("initial")]({ | ||
options | ||
}); | ||
export default function() { | ||
postman[Request]({ | ||
name: "Test Request", | ||
method: "POST", | ||
address: "http://graphql.example.com/", | ||
data: ${render(body)} | ||
}); | ||
} | ||
`) | ||
}) | ||
|
||
test('body var', async t => { | ||
const [ main ] = await convertFile( | ||
'test/material/2.1/graphql-body-var.json' | ||
) | ||
const query = '' + | ||
`query UserName($id: UserId) { | ||
user(id: $id) { | ||
name | ||
} | ||
}` | ||
const variables = '' + | ||
`{ | ||
\t"id": "{{userId}}" | ||
}` | ||
const body = { query, variables } | ||
t.is(main, `// Auto-generated by the Load Impact converter | ||
import "./libs/shim/core.js"; | ||
export let options = { maxRedirects: 4 }; | ||
const Request = Symbol.for("request"); | ||
postman[Symbol.for("initial")]({ | ||
options, | ||
collection: { | ||
userId: "5" | ||
} | ||
}); | ||
export default function() { | ||
postman[Request]({ | ||
name: "Test Request", | ||
method: "POST", | ||
address: "http://graphql.example.com/", | ||
data: | ||
${render(body)} | ||
}); | ||
} | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "a3033a78-1a2e-4036-9621-11bc4fdc3ad6", | ||
"name": "GraphQL", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Test Request", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "graphql", | ||
"graphql": { | ||
"query": "{\n user {\n name\n }\n}", | ||
"variables": "" | ||
} | ||
}, | ||
"url": { | ||
"raw": "http://graphql.example.com", | ||
"protocol": "http", | ||
"host": [ | ||
"graphql", | ||
"example", | ||
"com" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "a3033a78-1a2e-4036-9621-11bc4fdc3ad6", | ||
"name": "GraphQL", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Test Request", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "graphql", | ||
"graphql": { | ||
"query": "query UserName($id: UserId) {\n user(id: $id) {\n name\n }\n}", | ||
"variables": "{\n\t\"id\": \"{{userId}}\"\n}" | ||
} | ||
}, | ||
"url": { | ||
"raw": "http://graphql.example.com", | ||
"protocol": "http", | ||
"host": [ | ||
"graphql", | ||
"example", | ||
"com" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
], | ||
"variable": [ | ||
{ | ||
"id": "c910e57e-8c50-4ce0-aa13-6ab64f448421", | ||
"key": "userId", | ||
"value": "5", | ||
"type": "string" | ||
} | ||
] | ||
} |
Oops, something went wrong.