-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for fetching test suite configuration from graphql
- Loading branch information
1 parent
9155d6a
commit 5097b51
Showing
4 changed files
with
81 additions
and
6 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
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,68 @@ | ||
import fetch from "node-fetch"; | ||
import dbg from "debug"; | ||
|
||
const debug = dbg("replay:test-utils:config"); | ||
|
||
async function query(apiKey: string, name: string, query: string, variables = {}) { | ||
const options = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
name, | ||
variables, | ||
}), | ||
}; | ||
|
||
const server = process.env.REPLAY_API_SERVER || "https://api.replay.io"; | ||
debug("Querying %s graphql endpoint", server); | ||
const result = await fetch(`${server}/v1/graphql`, options); | ||
|
||
return await result.json(); | ||
} | ||
|
||
async function fetchWorkspaceConfig(apiKey: string) { | ||
const json = await query( | ||
apiKey, | ||
"GetWorkspaceConfig", | ||
` | ||
query GetWorkspaceConfig { | ||
auth { | ||
workspaces { | ||
edges { | ||
node { | ||
id | ||
settings { | ||
features | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
); | ||
|
||
if (json.errors) { | ||
debug("GraphQL failed: %s", json.errors); | ||
throw new Error(json.errors[0].message || "Unexpected error"); | ||
} | ||
|
||
const edges = json.data?.auth.workspaces.edges; | ||
if (!edges || edges.length !== 1) { | ||
debug("Failed to find workspace: %o", json.data); | ||
throw new Error("Failed to find a workspace for the given apiKey"); | ||
} | ||
|
||
debug("Workspace settings: %o", edges[0].node.settings); | ||
const features = edges[0].node.settings.features; | ||
|
||
return { | ||
env: features?.testSuites?.env || {}, | ||
}; | ||
} | ||
|
||
export { fetchWorkspaceConfig }; |
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