-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL Hive Plugin & Transform (#4854)
* GraphQL Hive Plugin * yarn.lock * Fix version * Fix typings * Update
- Loading branch information
Showing
14 changed files
with
745 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@graphql-mesh/config': patch | ||
'@graphql-mesh/types': patch | ||
'@graphql-mesh/plugin-hive': patch | ||
'@graphql-mesh/transform-hive': patch | ||
--- | ||
|
||
New GraphQL Hive plugin |
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,44 @@ | ||
{ | ||
"name": "@graphql-mesh/plugin-hive", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "Urigo/graphql-mesh", | ||
"directory": "packages/plugins/hive" | ||
}, | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./*": { | ||
"require": "./dist/*.js", | ||
"import": "./dist/*.mjs" | ||
} | ||
}, | ||
"typings": "dist/index.d.ts", | ||
"peerDependencies": { | ||
"graphql": "*" | ||
}, | ||
"dependencies": { | ||
"@graphql-hive/client": "0.21.1", | ||
"@graphql-mesh/cross-helpers": "0.2.10", | ||
"@graphql-mesh/string-interpolation": "0.3.3", | ||
"@graphql-mesh/types": "0.86.0", | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/http-cache-semantics": "4.0.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
}, | ||
"sideEffects": false, | ||
"typescript": { | ||
"definition": "dist/index.d.ts" | ||
} | ||
} |
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,81 @@ | ||
import { createHive, HivePluginOptions, useHive } from '@graphql-hive/client'; | ||
import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types'; | ||
import { process } from '@graphql-mesh/cross-helpers'; | ||
import { stringInterpolator } from '@graphql-mesh/string-interpolation'; | ||
|
||
export default function useMeshHive(pluginOptions: MeshPluginOptions<YamlConfig.HivePlugin>): MeshPlugin<{}> { | ||
const token = stringInterpolator.parse(pluginOptions.token, { | ||
env: process.env, | ||
}); | ||
if (!token) { | ||
return {}; | ||
} | ||
|
||
let usage: HivePluginOptions['usage']; | ||
if (pluginOptions.usage) { | ||
usage = { | ||
max: pluginOptions.usage.max, | ||
ttl: pluginOptions.usage.ttl, | ||
exclude: pluginOptions.usage.exclude, | ||
sampleRate: pluginOptions.usage.sampleRate, | ||
processVariables: pluginOptions.usage.processVariables, | ||
}; | ||
if (pluginOptions.usage?.clientInfo) { | ||
usage.clientInfo = function (context) { | ||
return { | ||
name: stringInterpolator.parse(pluginOptions.usage.clientInfo.name, { | ||
context, | ||
env: process.env, | ||
}), | ||
version: stringInterpolator.parse(pluginOptions.usage.clientInfo.version, { | ||
context, | ||
env: process.env, | ||
}), | ||
}; | ||
}; | ||
} | ||
} | ||
let reporting: HivePluginOptions['reporting']; | ||
if (pluginOptions.reporting) { | ||
reporting = { | ||
author: stringInterpolator.parse(pluginOptions.reporting.author, { env: process.env }), | ||
commit: stringInterpolator.parse(pluginOptions.reporting.commit, { env: process.env }), | ||
serviceName: stringInterpolator.parse(pluginOptions.reporting.serviceName, { | ||
env: process.env, | ||
}), | ||
serviceUrl: stringInterpolator.parse(pluginOptions.reporting.serviceUrl, { | ||
env: process.env, | ||
}), | ||
}; | ||
} | ||
let agent: HivePluginOptions['agent']; | ||
if (pluginOptions.agent) { | ||
agent = { | ||
timeout: pluginOptions.agent.timeout, | ||
maxRetries: pluginOptions.agent.maxRetries, | ||
minTimeout: pluginOptions.agent.minTimeout, | ||
sendInterval: pluginOptions.agent.sendInterval, | ||
maxSize: pluginOptions.agent.maxSize, | ||
logger: pluginOptions.logger, | ||
}; | ||
} | ||
const hiveClient = createHive({ | ||
enabled: true, | ||
debug: !!process.env.DEBUG, | ||
token, | ||
agent, | ||
usage, | ||
reporting, | ||
}); | ||
const id = pluginOptions.pubsub.subscribe('destroy', () => { | ||
hiveClient | ||
.dispose() | ||
.catch(e => pluginOptions.logger.error(`Hive client failed to dispose`, e)) | ||
.finally(() => pluginOptions.pubsub.unsubscribe(id)); | ||
}); | ||
return { | ||
onPluginInit({ addPlugin }) { | ||
addPlugin(useHive(hiveClient)); | ||
}, | ||
}; | ||
} |
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,106 @@ | ||
extend type Plugin { | ||
hive: HivePlugin | ||
} | ||
|
||
type HivePlugin @md { | ||
""" | ||
Access Token | ||
""" | ||
token: String! | ||
""" | ||
Agent Options | ||
""" | ||
agent: HiveAgentOptions | ||
""" | ||
Collects schema usage based on operations | ||
""" | ||
usage: HiveUsageOptions | ||
""" | ||
Schema reporting | ||
""" | ||
reporting: HiveReportingOptions | ||
} | ||
|
||
type HiveAgentOptions { | ||
""" | ||
30s by default | ||
""" | ||
timeout: Int | ||
""" | ||
5 by default | ||
""" | ||
maxRetries: Int | ||
""" | ||
200 by default | ||
""" | ||
minTimeout: Int | ||
""" | ||
Send reports in interval (defaults to 10_000ms) | ||
""" | ||
sendInterval: Int | ||
""" | ||
Max number of traces to send at once (defaults to 25) | ||
""" | ||
maxSize: Int | ||
} | ||
|
||
type HiveUsageOptions { | ||
""" | ||
Extract client info from GraphQL Context | ||
""" | ||
clientInfo: HiveClientInfo | ||
""" | ||
Hive uses LRU cache to store info about operations. | ||
This option represents the maximum size of the cache. | ||
Default: 1000 | ||
""" | ||
max: Int | ||
""" | ||
Hive uses LRU cache to store info about operations. | ||
This option represents the maximum age of an unused operation in the cache. | ||
Default: no ttl | ||
""" | ||
ttl: Int | ||
""" | ||
A list of operations (by name) to be ignored by Hive. | ||
""" | ||
exclude: [String] | ||
""" | ||
Sample rate to determine sampling. | ||
0.0 = 0% chance of being sent | ||
1.0 = 100% chance of being sent | ||
Default: 1.0 | ||
""" | ||
sampleRate: Float | ||
""" | ||
(Experimental) Enables collecting Input fields usage based on the variables passed to the operation. | ||
Default: false | ||
""" | ||
processVariables: Boolean | ||
} | ||
|
||
type HiveClientInfo { | ||
""" | ||
Extract client name | ||
Example: "{context.headers['x-client-name']}" | ||
""" | ||
name: String | ||
""" | ||
Extract client version | ||
Example: "{context.headers['x-client-version']}" | ||
""" | ||
version: String | ||
} | ||
|
||
type HiveReportingOptions { | ||
""" | ||
Author of current version of the schema | ||
""" | ||
author: String! | ||
""" | ||
Commit SHA hash (or any identifier) related to the schema version | ||
""" | ||
commit: String! | ||
serviceName: String | ||
serviceUrl: String | ||
} |
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
Oops, something went wrong.