graphile-build 4.8.0-rc.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +1 -0
  2. package/node8plus/Live.js.flow +3 -3
  3. package/node8plus/Live.js.map +1 -1
  4. package/node8plus/SchemaBuilder.d.ts +31 -1
  5. package/node8plus/SchemaBuilder.js +22 -3
  6. package/node8plus/SchemaBuilder.js.flow +33 -8
  7. package/node8plus/SchemaBuilder.js.map +1 -1
  8. package/node8plus/index.js +1 -1
  9. package/node8plus/index.js.flow +2 -0
  10. package/node8plus/index.js.map +1 -1
  11. package/node8plus/makeNewBuild.js +73 -1
  12. package/node8plus/makeNewBuild.js.flow +128 -4
  13. package/node8plus/makeNewBuild.js.map +1 -1
  14. package/node8plus/plugins/AddQueriesToSubscriptionsPlugin.js.flow +1 -1
  15. package/node8plus/plugins/AddQueriesToSubscriptionsPlugin.js.map +1 -1
  16. package/node8plus/plugins/ClientMutationIdDescriptionPlugin.js +3 -3
  17. package/node8plus/plugins/ClientMutationIdDescriptionPlugin.js.flow +9 -3
  18. package/node8plus/plugins/ClientMutationIdDescriptionPlugin.js.map +1 -1
  19. package/node8plus/plugins/MutationPayloadQueryPlugin.js +1 -1
  20. package/node8plus/plugins/MutationPayloadQueryPlugin.js.flow +3 -1
  21. package/node8plus/plugins/MutationPayloadQueryPlugin.js.map +1 -1
  22. package/node8plus/plugins/MutationPlugin.js +1 -1
  23. package/node8plus/plugins/MutationPlugin.js.flow +3 -1
  24. package/node8plus/plugins/MutationPlugin.js.map +1 -1
  25. package/node8plus/plugins/NodePlugin.js +5 -5
  26. package/node8plus/plugins/NodePlugin.js.flow +18 -5
  27. package/node8plus/plugins/NodePlugin.js.map +1 -1
  28. package/node8plus/plugins/QueryPlugin.js +2 -2
  29. package/node8plus/plugins/QueryPlugin.js.flow +6 -2
  30. package/node8plus/plugins/QueryPlugin.js.map +1 -1
  31. package/node8plus/plugins/StandardTypesPlugin.js +3 -3
  32. package/node8plus/plugins/StandardTypesPlugin.js.flow +10 -3
  33. package/node8plus/plugins/StandardTypesPlugin.js.map +1 -1
  34. package/node8plus/plugins/SubscriptionPlugin.js +1 -1
  35. package/node8plus/plugins/SubscriptionPlugin.js.flow +4 -1
  36. package/node8plus/plugins/SubscriptionPlugin.js.map +1 -1
  37. package/node8plus/plugins/TrimEmptyDescriptionsPlugin.js +54 -0
  38. package/node8plus/plugins/TrimEmptyDescriptionsPlugin.js.flow +40 -0
  39. package/node8plus/plugins/TrimEmptyDescriptionsPlugin.js.map +1 -0
  40. package/node8plus/plugins/index.js +8 -0
  41. package/node8plus/plugins/index.js.flow +2 -0
  42. package/node8plus/plugins/index.js.map +1 -1
  43. package/node8plus/swallowError.js.flow +1 -4
  44. package/node8plus/swallowError.js.map +1 -1
  45. package/node8plus/utils.js +44 -2
  46. package/node8plus/utils.js.flow +54 -5
  47. package/node8plus/utils.js.map +1 -1
  48. package/package.json +11 -11
package/README.md CHANGED
@@ -37,6 +37,7 @@ And please give some love to our featured sponsors 🤩:
37
37
  <table><tr>
38
38
  <td align="center"><a href="http://chads.website"><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
39
39
  <td align="center"><a href="https://storyscript.com/?utm_source=postgraphile"><img src="https://graphile.org/images/sponsors/storyscript.png" width="90" height="90" alt="Storyscript" /><br />Storyscript</a> *</td>
40
+ <td align="center"><a href="https://surge.io/"><img src="https://graphile.org/images/sponsors/surge.png" width="90" height="90" alt="Surge.io" /><br />Surge.io</a> *</td>
40
41
  <td align="center"><a href="https://postlight.com/?utm_source=graphile"><img src="https://graphile.org/images/sponsors/postlight.jpg" width="90" height="90" alt="Postlight" /><br />Postlight</a> *</td>
41
42
  </tr></table>
42
43
 
@@ -100,7 +100,7 @@ export class LiveMonitor {
100
100
  this.changeCallback = null;
101
101
  this.changeCounter = 0;
102
102
  this.liveConditionsByCounter = {};
103
- this.handleChange = function() {
103
+ this.handleChange = function () {
104
104
  /* This function is throttled to ~25ms (see constructor); it's purpose is
105
105
  * to bundle up all the changes that occur in a small window into the same
106
106
  * handle change flow, so _reallyHandleChange doesn't get called twice in
@@ -113,7 +113,7 @@ export class LiveMonitor {
113
113
  }
114
114
  };
115
115
 
116
- this._reallyHandleChange = function() {
116
+ this._reallyHandleChange = function () {
117
117
  // This function is throttled to MONITOR_THROTTLE_DURATION (see constructor)
118
118
  if (this.changeCallback) {
119
119
  // Convince Flow this won't suddenly become null
@@ -146,7 +146,7 @@ export class LiveMonitor {
146
146
  }
147
147
  };
148
148
 
149
- this.onChange = function(callback: () => void) {
149
+ this.onChange = function (callback: () => void) {
150
150
  if (this.released) {
151
151
  throw new Error("Monitors cannot be reused.");
152
152
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Live.js"],"names":["DEBOUNCE_DURATION","MONITOR_THROTTLE_DURATION","Math","max","parseInt","process","env","LIVE_THROTTLE","LiveSource","subscribeCollection","_callback","_collectionIdentifier","_predicate","subscribeRecord","_recordIdentifier","LiveProvider","constructor","namespace","sources","registerSource","source","push","collectionIdentifierIsValid","recordIdentifierIsValid","LiveMonitor","providers","extraRootValue","released","subscriptionReleasersByCounter","changeCallback","changeCounter","liveConditionsByCounter","handleChange","_reallyHandleChange","cb","counter","String","changeRootValue","liveCollection","bind","liveRecord","liveConditions","release","resetBefore","console","warn","onChange","callback","Error","setImmediate","leading","trailing","currentCounter","oldCounters","Object","keys","filter","n","oldCounter","releaser","cancel","Infinity","collectionIdentifier","predicate","provider","length","recordIdentifier","LiveCoordinator","subscribe","registerProvider","getMonitor","_parent","_args","_context","_info","monitor","liveAbort","e","iterator","throw","makeAsyncIteratorFromMonitor","onClose"],"mappings":";;;;;;;;AAEA;;AAEA;;;;AAHA;AAWA,MAAMA,iBAAiB,GAAG,EAA1B;AAEA,MAAMC,yBAAyB,GAAGC,IAAI,CAACC,GAAL,CAChCH,iBAAiB,GAAG,CADY,EAE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;AACrB;AAH8C,GAA1C,CAAP;AAKD","sourcesContent":["// @flow\n/* eslint-disable flowtype/no-weak-types */\nimport callbackToAsyncIterator from \"./callbackToAsyncIterator\";\nimport type { GraphQLResolveInfo } from \"graphql\";\nimport { throttle } from \"lodash\";\n\ntype SubscriptionReleaser = () => void;\ntype SubscriptionCallback = () => void;\n\ntype Predicate = (record: any) => boolean;\ntype PredicateGenerator = (data: any) => Predicate;\n\nconst DEBOUNCE_DURATION = 25;\n\nconst MONITOR_THROTTLE_DURATION = Math.max(\n DEBOUNCE_DURATION + 1,\n parseInt(process.env.LIVE_THROTTLE || \"\", 10) || 500\n);\n\n/*\n * Sources are long-lived (i.e. in \"watch\" mode you just re-use the same one\n * over and over) because there is no release for them\n */\nexport class LiveSource {\n subscribeCollection(\n _callback: SubscriptionCallback,\n _collectionIdentifier: any,\n _predicate?: Predicate\n ): SubscriptionReleaser | null {\n return null;\n }\n\n subscribeRecord(\n _callback: SubscriptionCallback,\n _collectionIdentifier: any,\n _recordIdentifier: any\n ): SubscriptionReleaser | null {\n return null;\n }\n}\n\n/*\n * Providers enable a namespace, perform validation, and track the sources used\n * by that namespace within one single schema build. The should not directly use\n * any long-lived features as they do not have an explicit \"release\"/\"close\"\n * command when a new schema is built.\n */\nexport class LiveProvider {\n sources: Array<LiveSource>;\n namespace: string;\n\n constructor(namespace: string) {\n this.namespace = namespace;\n this.sources = [];\n }\n\n registerSource(source: LiveSource) {\n this.sources.push(source);\n }\n\n collectionIdentifierIsValid(_collectionIdentifier: any): boolean {\n return false;\n }\n\n recordIdentifierIsValid(\n _collectionIdentifier: any,\n _recordIdentifier: any\n ): boolean {\n return false;\n }\n}\n\n/*\n * During a single execution of GraphQL (specifically a subscription request),\n * the LiveMonitor tracks the resources viewed and subscribes to updates in them.\n */\nexport class LiveMonitor {\n released: boolean;\n providers: { [namespace: string]: LiveProvider };\n subscriptionReleasersByCounter: {\n [counter: string]: (() => void)[],\n };\n liveConditionsByCounter: { [counter: string]: Array<PredicateGenerator> };\n changeCallback: ((arg: any) => void) | null;\n changeCounter: number;\n extraRootValue: any;\n\n handleChange: (() => void) | null;\n _reallyHandleChange: (() => void) | null;\n onChange: (callback: () => void) => () => void;\n\n constructor(\n providers: { [namespace: string]: LiveProvider },\n extraRootValue: any\n ) {\n this.extraRootValue = extraRootValue;\n this.released = false;\n this.providers = providers;\n this.subscriptionReleasersByCounter = {};\n this.changeCallback = null;\n this.changeCounter = 0;\n this.liveConditionsByCounter = {};\n this.handleChange = function() {\n /* This function is throttled to ~25ms (see constructor); it's purpose is\n * to bundle up all the changes that occur in a small window into the same\n * handle change flow, so _reallyHandleChange doesn't get called twice in\n * quick succession. _reallyHandleChange is then further throttled with a\n * larger window, BUT it triggers on both leading and trailing edge,\n * whereas this only triggers on the trailing edge.\n */\n if (this._reallyHandleChange) {\n this._reallyHandleChange();\n }\n };\n\n this._reallyHandleChange = function() {\n // This function is throttled to MONITOR_THROTTLE_DURATION (see constructor)\n if (this.changeCallback) {\n // Convince Flow this won't suddenly become null\n const cb = this.changeCallback;\n const counter = this.changeCounter++;\n /*\n * In live queries we need to know when the current result set has\n * finished being calculated so that we know we've received all the\n * liveRecord / liveCollection calls and can release the out of date\n * ones. To achieve this, we use a custom `subscribe` function which\n * calls `rootValue.release()` once the result set has been calculated.\n */\n this.subscriptionReleasersByCounter[String(counter)] = [];\n this.liveConditionsByCounter[String(counter)] = [];\n const changeRootValue = {\n ...this.extraRootValue,\n counter,\n liveCollection: this.liveCollection.bind(this, counter),\n liveRecord: this.liveRecord.bind(this, counter),\n liveConditions: this.liveConditionsByCounter[String(counter)],\n release: () => {\n // Despite it's name, this means that the execution has complete, which means we're actually releasing everything *before* this.\n this.resetBefore(counter);\n },\n };\n cb(changeRootValue);\n } else {\n // eslint-disable-next-line no-console\n console.warn(\"Change occurred, but no-one was listening\");\n }\n };\n\n this.onChange = function(callback: () => void) {\n if (this.released) {\n throw new Error(\"Monitors cannot be reused.\");\n }\n if (this.changeCallback) {\n throw new Error(\"Already monitoring for changes\");\n }\n // Throttle to every 250ms\n this.changeCallback = callback;\n if (this.handleChange) {\n setImmediate(this.handleChange);\n }\n return () => {\n if (this.changeCallback === callback) {\n this.changeCallback = null;\n }\n this.release();\n };\n };\n\n this.handleChange = throttle(\n this.handleChange.bind(this),\n DEBOUNCE_DURATION,\n {\n leading: false,\n trailing: true,\n }\n );\n if (!this._reallyHandleChange) {\n throw new Error(\"This is just to make flow happy\");\n }\n this._reallyHandleChange = throttle(\n this._reallyHandleChange.bind(this),\n MONITOR_THROTTLE_DURATION - DEBOUNCE_DURATION,\n {\n leading: true,\n trailing: true,\n }\n );\n this.onChange = this.onChange.bind(this);\n }\n\n resetBefore(currentCounter: number) {\n // Clear out of date subscriptionReleasers\n {\n const oldCounters = Object.keys(\n this.subscriptionReleasersByCounter\n ).filter(n => parseInt(n, 10) < currentCounter);\n for (const oldCounter of oldCounters) {\n for (const releaser of this.subscriptionReleasersByCounter[\n oldCounter\n ]) {\n releaser();\n }\n delete this.subscriptionReleasersByCounter[oldCounter];\n }\n }\n // Clear out of date liveConditions\n {\n const oldCounters = Object.keys(this.liveConditionsByCounter).filter(\n n => parseInt(n, 10) < currentCounter\n );\n for (const oldCounter of oldCounters) {\n delete this.liveConditionsByCounter[oldCounter];\n }\n }\n }\n\n release() {\n if (this.handleChange) {\n // $FlowFixMe: throttled function\n this.handleChange.cancel();\n }\n this.handleChange = null;\n if (this._reallyHandleChange) {\n // $FlowFixMe: throttled function\n this._reallyHandleChange.cancel();\n }\n this._reallyHandleChange = null;\n this.resetBefore(Infinity);\n this.providers = {};\n this.released = true;\n }\n\n liveCollection(\n counter: number,\n namespace: string,\n collectionIdentifier: any,\n predicate: (record: any) => boolean = () => true\n ) {\n const handleChange = this.handleChange;\n if (this.released || !handleChange) {\n return;\n }\n const provider = this.providers[namespace];\n if (!provider || provider.sources.length === 0) return;\n if (!provider.collectionIdentifierIsValid(collectionIdentifier)) {\n throw new Error(\n `Invalid collection identifier passed to LiveMonitor[${namespace}]: ${collectionIdentifier}`\n );\n }\n for (const source of provider.sources) {\n const releaser = source.subscribeCollection(\n handleChange,\n collectionIdentifier,\n predicate\n );\n if (releaser) {\n this.subscriptionReleasersByCounter[String(counter)].push(releaser);\n }\n }\n }\n\n liveRecord(\n counter: number,\n namespace: string,\n collectionIdentifier: any,\n recordIdentifier: any\n ) {\n const handleChange = this.handleChange;\n if (this.released || !handleChange) {\n return;\n }\n // TODO: if (recordIdentifier == null) {return}\n const provider = this.providers[namespace];\n if (!provider || provider.sources.length === 0) return;\n if (!provider.collectionIdentifierIsValid(collectionIdentifier)) {\n throw new Error(\n `Invalid collection identifier passed to LiveMonitor[${namespace}]: ${collectionIdentifier}`\n );\n }\n if (\n !provider.recordIdentifierIsValid(collectionIdentifier, recordIdentifier)\n ) {\n throw new Error(\n `Invalid record identifier passed to LiveMonitor[${namespace}]: ${collectionIdentifier}`\n );\n }\n for (const source of provider.sources) {\n const releaser = source.subscribeRecord(\n handleChange,\n collectionIdentifier,\n recordIdentifier\n );\n if (releaser) {\n this.subscriptionReleasersByCounter[String(counter)].push(releaser);\n }\n }\n }\n}\n\n/*\n * There is one coordinator for each build of the GraphQL schema, it tracks the providers\n * and gives a handy `subscribe` method that can be used for live queries (assuming\n * that the `resolve` is provided the same as in a Query).\n */\nexport class LiveCoordinator {\n providers: { [namespace: string]: LiveProvider };\n\n constructor() {\n this.providers = {};\n this.subscribe = this.subscribe.bind(this);\n }\n\n registerProvider(provider: LiveProvider) {\n const { namespace } = provider;\n if (this.providers[namespace]) {\n throw new Error(`Namespace ${namespace} already registered with Live`);\n }\n this.providers[namespace] = provider;\n }\n\n registerSource(namespace: string, source: LiveSource) {\n if (!this.providers[namespace]) {\n // eslint-disable-next-line no-console\n console.warn(\n `LiveProvider '${namespace}' is not registered, skipping live source.`\n );\n return;\n }\n this.providers[namespace].registerSource(source);\n }\n\n getMonitor(extraRootValue: any) {\n return new LiveMonitor(this.providers, extraRootValue);\n }\n\n // Tell Flow that we're okay with overwriting this\n subscribe: (\n _parent: any,\n _args: any,\n context: any,\n _info: GraphQLResolveInfo\n ) => any;\n subscribe(\n _parent: any,\n _args: any,\n _context: any,\n _info: GraphQLResolveInfo\n ) {\n const monitor = this.getMonitor({\n liveAbort: e => {\n if (iterator) iterator.throw(e);\n },\n });\n const iterator = makeAsyncIteratorFromMonitor(monitor);\n return iterator;\n }\n}\n\nexport function makeAsyncIteratorFromMonitor(monitor: LiveMonitor) {\n return callbackToAsyncIterator(monitor.onChange, {\n onClose: release => {\n if (release) release();\n },\n });\n}\n"],"file":"Live.js"}
1
+ {"version":3,"sources":["../src/Live.js"],"names":["DEBOUNCE_DURATION","MONITOR_THROTTLE_DURATION","Math","max","parseInt","process","env","LIVE_THROTTLE","LiveSource","subscribeCollection","_callback","_collectionIdentifier","_predicate","subscribeRecord","_recordIdentifier","LiveProvider","constructor","namespace","sources","registerSource","source","push","collectionIdentifierIsValid","recordIdentifierIsValid","LiveMonitor","providers","extraRootValue","released","subscriptionReleasersByCounter","changeCallback","changeCounter","liveConditionsByCounter","handleChange","_reallyHandleChange","cb","counter","String","changeRootValue","liveCollection","bind","liveRecord","liveConditions","release","resetBefore","console","warn","onChange","callback","Error","setImmediate","leading","trailing","currentCounter","oldCounters","Object","keys","filter","n","oldCounter","releaser","cancel","Infinity","collectionIdentifier","predicate","provider","length","recordIdentifier","LiveCoordinator","subscribe","registerProvider","getMonitor","_parent","_args","_context","_info","monitor","liveAbort","e","iterator","throw","makeAsyncIteratorFromMonitor","onClose"],"mappings":";;;;;;;;AAEA;;AAEA;;;;AAHA;AAWA,MAAMA,iBAAiB,GAAG,EAA1B;AAEA,MAAMC,yBAAyB,GAAGC,IAAI,CAACC,GAAL,CAChCH,iBAAiB,GAAG,CADY,EAEhCI,QAAQ,CAACC,OAAO,CAACC,GAAR,CAAYC,aAAZ,IAA6B,EAA9B,EAAkC,EAAlC,CAAR,IAAiD,GAFjB,CAAlC;AAKA;;;;;AAIO,MAAMC,UAAN,CA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B;;AACA,QAAI,KAAKvC,SAAL,CAAeR,SAAf,CAAJ,EAA+B;AAC7B,YAAM,IAAI+B,KAAJ,CAAW,aAAY/B,SAAU,+BAAjC,CAAN;AACD;;AACD,SAAKQ,SAAL,CAAeR,SAAf,IAA4B+C,QAA5B;AACD;;AAED7C,EAAAA,cAAc,CAACF,SAAD,EAAoBG,MAApB,EAAwC;AACpD,QAAI,CAAC,KAAKK,SAAL,CAAeR,SAAf,CAAL,EAAgC;AAC9B;AACA2B,MAAAA,OAAO,CAACC,IAAR,CACG,iBAAgB5B,SAAU,4CAD7B;AAGA;AACD;;AACD,SAAKQ,SAAL,CAAeR,SAAf,EAA0BE,cAA1B,CAAyCC,MAAzC;AACD;;AAEDkD,EAAAA,UAAU,CAAC5C,cAAD,EAAsB;AAC9B,WAAO,IAAIF,WAAJ,CAAgB,KAAKC,SAArB,EAAgCC,cAAhC,CAAP;AACD,GA7B0B,CA+B3B;;;AAOA0C,EAAAA,SAAS,CACPG,OADO,EAEPC,KAFO,EAGPC,QAHO,EAIPC,KAJO,EAKP;AACA,UAAMC,OAAO,GAAG,KAAKL,UAAL,CAAgB;AAC9BM,MAAAA,SAAS,EAAEC,CAAC,IAAI;AACd,YAAIC,QAAJ,EAAcA,QAAQ,CAACC,KAAT,CAAeF,CAAf;AACf;AAH6B,KAAhB,CAAhB;AAKA,UAAMC,QAAQ,GAAGE,4BAA4B,CAACL,OAAD,CAA7C;AACA,WAAOG,QAAP;AACD;;AAnD0B;;;;AAsDtB,SAASE,4BAAT,CAAsCL,OAAtC,EAA4D;AACjE,SAAO,sCAAwBA,OAAO,CAAC7B,QAAhC,EAA0C;AAC/CmC,IAAAA,OAAO,EAAEvC,OAAO,IAAI;AAClB,UAAIA,OAAJ,EAAaA,OAAO;AACrB;AAH8C,GAA1C,CAAP;AAKD","sourcesContent":["// @flow\n/* eslint-disable flowtype/no-weak-types */\nimport callbackToAsyncIterator from \"./callbackToAsyncIterator\";\nimport type { GraphQLResolveInfo } from \"graphql\";\nimport { throttle } from \"lodash\";\n\ntype SubscriptionReleaser = () => void;\ntype SubscriptionCallback = () => void;\n\ntype Predicate = (record: any) => boolean;\ntype PredicateGenerator = (data: any) => Predicate;\n\nconst DEBOUNCE_DURATION = 25;\n\nconst MONITOR_THROTTLE_DURATION = Math.max(\n DEBOUNCE_DURATION + 1,\n parseInt(process.env.LIVE_THROTTLE || \"\", 10) || 500\n);\n\n/*\n * Sources are long-lived (i.e. in \"watch\" mode you just re-use the same one\n * over and over) because there is no release for them\n */\nexport class LiveSource {\n subscribeCollection(\n _callback: SubscriptionCallback,\n _collectionIdentifier: any,\n _predicate?: Predicate\n ): SubscriptionReleaser | null {\n return null;\n }\n\n subscribeRecord(\n _callback: SubscriptionCallback,\n _collectionIdentifier: any,\n _recordIdentifier: any\n ): SubscriptionReleaser | null {\n return null;\n }\n}\n\n/*\n * Providers enable a namespace, perform validation, and track the sources used\n * by that namespace within one single schema build. The should not directly use\n * any long-lived features as they do not have an explicit \"release\"/\"close\"\n * command when a new schema is built.\n */\nexport class LiveProvider {\n sources: Array<LiveSource>;\n namespace: string;\n\n constructor(namespace: string) {\n this.namespace = namespace;\n this.sources = [];\n }\n\n registerSource(source: LiveSource) {\n this.sources.push(source);\n }\n\n collectionIdentifierIsValid(_collectionIdentifier: any): boolean {\n return false;\n }\n\n recordIdentifierIsValid(\n _collectionIdentifier: any,\n _recordIdentifier: any\n ): boolean {\n return false;\n }\n}\n\n/*\n * During a single execution of GraphQL (specifically a subscription request),\n * the LiveMonitor tracks the resources viewed and subscribes to updates in them.\n */\nexport class LiveMonitor {\n released: boolean;\n providers: { [namespace: string]: LiveProvider };\n subscriptionReleasersByCounter: {\n [counter: string]: (() => void)[],\n };\n liveConditionsByCounter: { [counter: string]: Array<PredicateGenerator> };\n changeCallback: ((arg: any) => void) | null;\n changeCounter: number;\n extraRootValue: any;\n\n handleChange: (() => void) | null;\n _reallyHandleChange: (() => void) | null;\n onChange: (callback: () => void) => () => void;\n\n constructor(\n providers: { [namespace: string]: LiveProvider },\n extraRootValue: any\n ) {\n this.extraRootValue = extraRootValue;\n this.released = false;\n this.providers = providers;\n this.subscriptionReleasersByCounter = {};\n this.changeCallback = null;\n this.changeCounter = 0;\n this.liveConditionsByCounter = {};\n this.handleChange = function () {\n /* This function is throttled to ~25ms (see constructor); it's purpose is\n * to bundle up all the changes that occur in a small window into the same\n * handle change flow, so _reallyHandleChange doesn't get called twice in\n * quick succession. _reallyHandleChange is then further throttled with a\n * larger window, BUT it triggers on both leading and trailing edge,\n * whereas this only triggers on the trailing edge.\n */\n if (this._reallyHandleChange) {\n this._reallyHandleChange();\n }\n };\n\n this._reallyHandleChange = function () {\n // This function is throttled to MONITOR_THROTTLE_DURATION (see constructor)\n if (this.changeCallback) {\n // Convince Flow this won't suddenly become null\n const cb = this.changeCallback;\n const counter = this.changeCounter++;\n /*\n * In live queries we need to know when the current result set has\n * finished being calculated so that we know we've received all the\n * liveRecord / liveCollection calls and can release the out of date\n * ones. To achieve this, we use a custom `subscribe` function which\n * calls `rootValue.release()` once the result set has been calculated.\n */\n this.subscriptionReleasersByCounter[String(counter)] = [];\n this.liveConditionsByCounter[String(counter)] = [];\n const changeRootValue = {\n ...this.extraRootValue,\n counter,\n liveCollection: this.liveCollection.bind(this, counter),\n liveRecord: this.liveRecord.bind(this, counter),\n liveConditions: this.liveConditionsByCounter[String(counter)],\n release: () => {\n // Despite it's name, this means that the execution has complete, which means we're actually releasing everything *before* this.\n this.resetBefore(counter);\n },\n };\n cb(changeRootValue);\n } else {\n // eslint-disable-next-line no-console\n console.warn(\"Change occurred, but no-one was listening\");\n }\n };\n\n this.onChange = function (callback: () => void) {\n if (this.released) {\n throw new Error(\"Monitors cannot be reused.\");\n }\n if (this.changeCallback) {\n throw new Error(\"Already monitoring for changes\");\n }\n // Throttle to every 250ms\n this.changeCallback = callback;\n if (this.handleChange) {\n setImmediate(this.handleChange);\n }\n return () => {\n if (this.changeCallback === callback) {\n this.changeCallback = null;\n }\n this.release();\n };\n };\n\n this.handleChange = throttle(\n this.handleChange.bind(this),\n DEBOUNCE_DURATION,\n {\n leading: false,\n trailing: true,\n }\n );\n if (!this._reallyHandleChange) {\n throw new Error(\"This is just to make flow happy\");\n }\n this._reallyHandleChange = throttle(\n this._reallyHandleChange.bind(this),\n MONITOR_THROTTLE_DURATION - DEBOUNCE_DURATION,\n {\n leading: true,\n trailing: true,\n }\n );\n this.onChange = this.onChange.bind(this);\n }\n\n resetBefore(currentCounter: number) {\n // Clear out of date subscriptionReleasers\n {\n const oldCounters = Object.keys(\n this.subscriptionReleasersByCounter\n ).filter(n => parseInt(n, 10) < currentCounter);\n for (const oldCounter of oldCounters) {\n for (const releaser of this.subscriptionReleasersByCounter[\n oldCounter\n ]) {\n releaser();\n }\n delete this.subscriptionReleasersByCounter[oldCounter];\n }\n }\n // Clear out of date liveConditions\n {\n const oldCounters = Object.keys(this.liveConditionsByCounter).filter(\n n => parseInt(n, 10) < currentCounter\n );\n for (const oldCounter of oldCounters) {\n delete this.liveConditionsByCounter[oldCounter];\n }\n }\n }\n\n release() {\n if (this.handleChange) {\n // $FlowFixMe: throttled function\n this.handleChange.cancel();\n }\n this.handleChange = null;\n if (this._reallyHandleChange) {\n // $FlowFixMe: throttled function\n this._reallyHandleChange.cancel();\n }\n this._reallyHandleChange = null;\n this.resetBefore(Infinity);\n this.providers = {};\n this.released = true;\n }\n\n liveCollection(\n counter: number,\n namespace: string,\n collectionIdentifier: any,\n predicate: (record: any) => boolean = () => true\n ) {\n const handleChange = this.handleChange;\n if (this.released || !handleChange) {\n return;\n }\n const provider = this.providers[namespace];\n if (!provider || provider.sources.length === 0) return;\n if (!provider.collectionIdentifierIsValid(collectionIdentifier)) {\n throw new Error(\n `Invalid collection identifier passed to LiveMonitor[${namespace}]: ${collectionIdentifier}`\n );\n }\n for (const source of provider.sources) {\n const releaser = source.subscribeCollection(\n handleChange,\n collectionIdentifier,\n predicate\n );\n if (releaser) {\n this.subscriptionReleasersByCounter[String(counter)].push(releaser);\n }\n }\n }\n\n liveRecord(\n counter: number,\n namespace: string,\n collectionIdentifier: any,\n recordIdentifier: any\n ) {\n const handleChange = this.handleChange;\n if (this.released || !handleChange) {\n return;\n }\n // TODO: if (recordIdentifier == null) {return}\n const provider = this.providers[namespace];\n if (!provider || provider.sources.length === 0) return;\n if (!provider.collectionIdentifierIsValid(collectionIdentifier)) {\n throw new Error(\n `Invalid collection identifier passed to LiveMonitor[${namespace}]: ${collectionIdentifier}`\n );\n }\n if (\n !provider.recordIdentifierIsValid(collectionIdentifier, recordIdentifier)\n ) {\n throw new Error(\n `Invalid record identifier passed to LiveMonitor[${namespace}]: ${collectionIdentifier}`\n );\n }\n for (const source of provider.sources) {\n const releaser = source.subscribeRecord(\n handleChange,\n collectionIdentifier,\n recordIdentifier\n );\n if (releaser) {\n this.subscriptionReleasersByCounter[String(counter)].push(releaser);\n }\n }\n }\n}\n\n/*\n * There is one coordinator for each build of the GraphQL schema, it tracks the providers\n * and gives a handy `subscribe` method that can be used for live queries (assuming\n * that the `resolve` is provided the same as in a Query).\n */\nexport class LiveCoordinator {\n providers: { [namespace: string]: LiveProvider };\n\n constructor() {\n this.providers = {};\n this.subscribe = this.subscribe.bind(this);\n }\n\n registerProvider(provider: LiveProvider) {\n const { namespace } = provider;\n if (this.providers[namespace]) {\n throw new Error(`Namespace ${namespace} already registered with Live`);\n }\n this.providers[namespace] = provider;\n }\n\n registerSource(namespace: string, source: LiveSource) {\n if (!this.providers[namespace]) {\n // eslint-disable-next-line no-console\n console.warn(\n `LiveProvider '${namespace}' is not registered, skipping live source.`\n );\n return;\n }\n this.providers[namespace].registerSource(source);\n }\n\n getMonitor(extraRootValue: any) {\n return new LiveMonitor(this.providers, extraRootValue);\n }\n\n // Tell Flow that we're okay with overwriting this\n subscribe: (\n _parent: any,\n _args: any,\n context: any,\n _info: GraphQLResolveInfo\n ) => any;\n subscribe(\n _parent: any,\n _args: any,\n _context: any,\n _info: GraphQLResolveInfo\n ) {\n const monitor = this.getMonitor({\n liveAbort: e => {\n if (iterator) iterator.throw(e);\n },\n });\n const iterator = makeAsyncIteratorFromMonitor(monitor);\n return iterator;\n }\n}\n\nexport function makeAsyncIteratorFromMonitor(monitor: LiveMonitor) {\n return callbackToAsyncIterator(monitor.onChange, {\n onClose: release => {\n if (release) release();\n },\n });\n}\n"],"file":"Live.js"}
@@ -14,10 +14,11 @@ import {
14
14
  GraphQLInputFieldConfigMap,
15
15
  GraphQLInputFieldConfig,
16
16
  GraphQLUnionTypeConfig,
17
+ GraphQLInterfaceTypeConfig,
17
18
  } from "graphql";
18
19
  import { EventEmitter } from "events";
19
20
 
20
- type mixed = {} | string | number | boolean | undefined | null;
21
+ type mixed = Record<string, any> | string | number | boolean | undefined | null;
21
22
 
22
23
  export interface Options {
23
24
  [str: string]: any;
@@ -45,6 +46,7 @@ export interface Build {
45
46
  export interface Inflection {
46
47
  [str: string]: any;
47
48
  }
49
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
50
  export interface Scope<Type> {
49
51
  [str: string]: any;
50
52
  }
@@ -181,6 +183,34 @@ export default class SchemaBuilder extends EventEmitter {
181
183
  before?: Array<string>,
182
184
  after?: Array<string>
183
185
  ): void;
186
+ hook<TSource, TContext>(
187
+ hookName: "GraphQLInterfaceType",
188
+ fn: Hook<GraphQLInterfaceTypeConfig<TSource, TContext>>,
189
+ provides?: Array<string>,
190
+ before?: Array<string>,
191
+ after?: Array<string>
192
+ ): void;
193
+ hook<TSource, TContext>(
194
+ hookName: "GraphQLInterfaceType:fields",
195
+ fn: Hook<GraphQLFieldConfigMap<TSource, TContext>>,
196
+ provides?: Array<string>,
197
+ before?: Array<string>,
198
+ after?: Array<string>
199
+ ): void;
200
+ hook<TSource, TContext>(
201
+ hookName: "GraphQLInterfaceType:fields:field",
202
+ fn: Hook<GraphQLFieldConfig<TSource, TContext>>,
203
+ provides?: Array<string>,
204
+ before?: Array<string>,
205
+ after?: Array<string>
206
+ ): void;
207
+ hook(
208
+ hookName: "GraphQLInterfaceType:fields:field:args",
209
+ fn: Hook<GraphQLFieldConfigArgumentMap>,
210
+ provides?: Array<string>,
211
+ before?: Array<string>,
212
+ after?: Array<string>
213
+ ): void;
184
214
  hook(
185
215
  hookName: "finalize",
186
216
  fn: Hook<GraphQLSchema>,
@@ -17,7 +17,7 @@ var _events = _interopRequireDefault(require("events"));
17
17
 
18
18
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
19
 
20
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
21
 
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
@@ -96,7 +96,19 @@ class SchemaBuilder extends _events.default {
96
96
  // - 'GraphQLUnionType' to add any root-level attributes, e.g. add a description
97
97
  // - 'GraphQLUnionType:types' to add additional types to this union
98
98
  GraphQLUnionType: [],
99
- "GraphQLUnionType:types": []
99
+ "GraphQLUnionType:types": [],
100
+ // When creating a GraphQLInterfaceType via `newWithHooks`, we'll
101
+ // execute, the following hooks:
102
+ // - 'GraphQLInterfaceType' to add any root-level attributes, e.g. add a description
103
+ // - 'GraphQLInterfaceType:fields' to add additional fields to this interface type (is
104
+ // ran asynchronously and gets a reference to the final GraphQL Interface as
105
+ // `Self` in the context)
106
+ // - 'GraphQLInterfaceType:fields:field' to customise an individual field from above
107
+ // - 'GraphQLInterfaceType:fields:field:args' to customize the arguments to a field
108
+ GraphQLInterfaceType: [],
109
+ "GraphQLInterfaceType:fields": [],
110
+ "GraphQLInterfaceType:fields:field": [],
111
+ "GraphQLInterfaceType:fields:field:args": []
100
112
  };
101
113
  }
102
114
 
@@ -325,7 +337,14 @@ class SchemaBuilder extends _events.default {
325
337
  __origin: `GraphQL built-in`,
326
338
  isSchema: true
327
339
  });
328
- this._generatedSchema = this.applyHooks(build, "finalize", schema, {}, "Finalising GraphQL schema");
340
+ const hookedSchema = this.applyHooks(build, "finalize", schema, {}, "Finalising GraphQL schema");
341
+ const errors = build.graphql.validateSchema(hookedSchema);
342
+
343
+ if (errors && errors.length) {
344
+ throw new Error("GraphQL schema is invalid:\n" + errors.map(e => `- ` + e.message.replace(/\n/g, "\n ")).join("\n"));
345
+ }
346
+
347
+ this._generatedSchema = hookedSchema;
329
348
  }
330
349
 
331
350
  if (!this._generatedSchema) {
@@ -71,6 +71,10 @@ export type Build = {|
71
71
  // eslint-disable-next-line flowtype/no-weak-types
72
72
  [string]: (...args: Array<any>) => string,
73
73
  },
74
+ wrapDescription: (
75
+ description: string,
76
+ position: "root" | "type" | "field" | "arg"
77
+ ) => string,
74
78
  swallowError: (e: Error) => void,
75
79
  // resolveNode: EXPERIMENTAL, API might change!
76
80
  resolveNode: resolveNode,
@@ -227,6 +231,19 @@ class SchemaBuilder extends EventEmitter {
227
231
  // - 'GraphQLUnionType:types' to add additional types to this union
228
232
  GraphQLUnionType: [],
229
233
  "GraphQLUnionType:types": [],
234
+
235
+ // When creating a GraphQLInterfaceType via `newWithHooks`, we'll
236
+ // execute, the following hooks:
237
+ // - 'GraphQLInterfaceType' to add any root-level attributes, e.g. add a description
238
+ // - 'GraphQLInterfaceType:fields' to add additional fields to this interface type (is
239
+ // ran asynchronously and gets a reference to the final GraphQL Interface as
240
+ // `Self` in the context)
241
+ // - 'GraphQLInterfaceType:fields:field' to customise an individual field from above
242
+ // - 'GraphQLInterfaceType:fields:field:args' to customize the arguments to a field
243
+ GraphQLInterfaceType: [],
244
+ "GraphQLInterfaceType:fields": [],
245
+ "GraphQLInterfaceType:fields:field": [],
246
+ "GraphQLInterfaceType:fields:field:args": [],
230
247
  };
231
248
  }
232
249
 
@@ -253,12 +270,12 @@ class SchemaBuilder extends EventEmitter {
253
270
  throw new Error(`Sorry, '${hookName}' is not a supported hook`);
254
271
  }
255
272
  if (this._currentPluginName) {
256
- fn.displayName = `${this._currentPluginName}/${hookName}/${(provides &&
257
- provides.length &&
258
- provides.join("+")) ||
273
+ fn.displayName = `${this._currentPluginName}/${hookName}/${
274
+ (provides && provides.length && provides.join("+")) ||
259
275
  fn.displayName ||
260
276
  fn.name ||
261
- "unnamed"}`;
277
+ "unnamed"
278
+ }`;
262
279
  }
263
280
  if (provides) {
264
281
  if (!fn.displayName && provides.length) {
@@ -416,9 +433,9 @@ class SchemaBuilder extends EventEmitter {
416
433
 
417
434
  if (!newObj) {
418
435
  throw new Error(
419
- `Hook '${hook.displayName ||
420
- hook.name ||
421
- "anonymous"}' for '${hookName}' returned falsy value '${newObj}'`
436
+ `Hook '${
437
+ hook.displayName || hook.name || "anonymous"
438
+ }' for '${hookName}' returned falsy value '${newObj}'`
422
439
  );
423
440
  }
424
441
  debug(
@@ -484,13 +501,21 @@ class SchemaBuilder extends EventEmitter {
484
501
  isSchema: true,
485
502
  }
486
503
  );
487
- this._generatedSchema = this.applyHooks(
504
+ const hookedSchema = this.applyHooks(
488
505
  build,
489
506
  "finalize",
490
507
  schema,
491
508
  {},
492
509
  "Finalising GraphQL schema"
493
510
  );
511
+ const errors = build.graphql.validateSchema(hookedSchema);
512
+ if (errors && errors.length) {
513
+ throw new Error(
514
+ "GraphQL schema is invalid:\n" +
515
+ errors.map(e => `- ` + e.message.replace(/\n/g, "\n ")).join("\n")
516
+ );
517
+ }
518
+ this._generatedSchema = hookedSchema;
494
519
  }
495
520
  if (!this._generatedSchema) {
496
521
  throw new Error("Schema generation failed");
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/SchemaBuilder.js"],"names":["GraphQLSchema","graphql","debug","INDENT","SchemaBuilder","EventEmitter","constructor","options","Error","_busy","_watching","watchers","unwatchers","depth","hooks","build","inflection","init","finalize","GraphQLObjectType","GraphQLInputObjectType","GraphQLEnumType","GraphQLUnionType","_setPluginName","name","_currentPluginName","hook","hookName","fn","provides","before","after","displayName","length","join","push","relevantHooks","minIndex","minReason","maxIndex","maxReason","newProvides","newBefore","newAfter","describe","index","check","setMin","newMin","reason","setMax","newMax","forEach","oldHook","idx","oldProvides","oldBefore","oldAfter","some","dep","includes","splice","applyHooks","input","context","debugStr","repeat","newObj","hookDisplayName","previousHookName","status","currentHookName","previousHookEvent","currentHookEvent","oldObj","console","warn","Object","assign","registerWatcher","listen","unlisten","createBuild","initialBuild","scope","keys","filter","key","freeze","buildSchema","_generatedSchema","schema","newWithHooks","directives","specifiedDirectives","__origin","isSchema","watchSchema","listener","_explicitSchemaListener","ignoreChangeTriggers","triggerChange","emit","e","error","on","unwatchSchema","e2","removeListener"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAOA;;;;;;;;AAWA,MAAM;AAAEA,EAAAA;AAAF,IAAoBC,OAA1B;AAEA,MAAMC,KAAK,GAAG,oBAAa,kBAAb,CAAd;AAEA,MAAMC,MAAM,GAAG,IAAf;;AA2GA,MAAMC,aAAN,SAA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AL,CAAQ,QAAR,EAAkBP,QAAlB;AACD;;AACD,aAAKI,IAAL,CAAU,QAAV,EAAoB,KAAKb,WAAL,EAApB;AACD,OAdD,CAcE,OAAOc,CAAP,EAAU;AACV,YAAI;AACF,eAAK9F,KAAL,GAAa,KAAb,CADE,CAEF;;AACA,gBAAM,KAAKiG,aAAL,EAAN;AACD,SAJD,CAIE,OAAOC,EAAP,EAAW;AACXhC,UAAAA,OAAO,CAAC6B,KAAR,CACG,iEAAgED,CAAE,EADrE;AAGD;;AACD,cAAMA,CAAN;AACD;AACF,KAtDD,SAsDU;AACR,WAAK9F,KAAL,GAAa,KAAb;AACD;AACF;;AAED,QAAMiG,aAAN,GAAsB;AACpB,QAAI,KAAKjG,KAAT,EAAgB;AACd,YAAM,IAAID,KAAJ,CAAU,6BAAV,CAAN;AACD;;AACD,QAAI,CAAC,KAAKE,SAAV,EAAqB;AACnB,YAAM,IAAIF,KAAJ,CAAU,iCAAV,CAAN;AACD;;AACD,SAAKC,KAAL,GAAa,IAAb;;AACA,QAAI;AACF,YAAMyF,QAAQ,GAAG,KAAKC,uBAAtB;AACA,WAAKA,uBAAL,GAA+B,IAA/B;;AACA,UAAID,QAAJ,EAAc;AACZ,aAAKU,cAAL,CAAoB,QAApB,EAA8BV,QAA9B;AACD;;AACD,UAAI,KAAKG,aAAT,EAAwB;AACtB,aAAK,MAAMzE,EAAX,IAAiB,KAAKhB,UAAtB,EAAkC;AAChC,gBAAMgB,EAAE,CAAC,KAAKyE,aAAN,CAAR;AACD;AACF;;AACD,WAAKA,aAAL,GAAqB,IAArB;AACA,WAAK3F,SAAL,GAAiB,KAAjB;AACD,KAbD,SAaU;AACR,WAAKD,KAAL,GAAa,KAAb;AACD;AACF;;AA3csC;;eA8c1BL,a","sourcesContent":["// @flow\nimport debugFactory from \"debug\";\nimport makeNewBuild from \"./makeNewBuild\";\nimport { bindAll } from \"./utils\";\nimport * as graphql from \"graphql\";\nimport type {\n GraphQLType,\n GraphQLNamedType,\n GraphQLInterfaceType,\n GraphQLObjectTypeConfig,\n} from \"graphql\";\nimport EventEmitter from \"events\";\n// TODO: when we move to TypeScript, change this to:\n// import { EventEmitter } from \"events\";\nimport type {\n simplifyParsedResolveInfoFragmentWithType,\n parseResolveInfo,\n} from \"graphql-parse-resolve-info\";\nimport type { GraphQLResolveInfo } from \"graphql/type/definition\";\nimport type resolveNode from \"./resolveNode\";\n\nimport type { FieldWithHooksFunction } from \"./makeNewBuild\";\nconst { GraphQLSchema } = graphql;\n\nconst debug = debugFactory(\"graphile-builder\");\n\nconst INDENT = \" \";\n\nexport type Options = {\n [string]: mixed,\n};\n\nexport type Plugin = (\n builder: SchemaBuilder,\n options: Options\n) => Promise<void> | void;\n\ntype TriggerChangeType = () => void;\n\nexport type DataForType = {\n [string]: Array<mixed>,\n};\n\nexport type Build = {|\n graphileBuildVersion: string,\n graphql: *,\n parseResolveInfo: parseResolveInfo,\n simplifyParsedResolveInfoFragmentWithType: simplifyParsedResolveInfoFragmentWithType,\n // DEPRECATED: getAliasFromResolveInfo: (resolveInfo: GraphQLResolveInfo) => string,\n getSafeAliasFromResolveInfo: (resolveInfo: GraphQLResolveInfo) => string,\n getSafeAliasFromAlias: (alias: string) => string,\n resolveAlias(\n data: {},\n _args: mixed,\n _context: mixed,\n resolveInfo: GraphQLResolveInfo\n ): string,\n addType(type: GraphQLNamedType, origin?: ?string): void,\n getTypeByName(typeName: string): ?GraphQLType,\n extend<Obj1: *, Obj2: *>(base: Obj1, extra: Obj2, hint?: string): Obj1 & Obj2,\n newWithHooks<T: GraphQLNamedType | GraphQLSchema, ConfigType: *>(\n Class<T>,\n spec: ConfigType,\n scope: Scope,\n performNonEmptyFieldsCheck?: boolean\n ): ?T,\n fieldDataGeneratorsByType: Map<*, *>, // @deprecated - use fieldDataGeneratorsByFieldNameByType instead\n fieldDataGeneratorsByFieldNameByType: Map<*, *>,\n fieldArgDataGeneratorsByFieldNameByType: Map<*, *>,\n inflection: {\n // eslint-disable-next-line flowtype/no-weak-types\n [string]: (...args: Array<any>) => string,\n },\n swallowError: (e: Error) => void,\n // resolveNode: EXPERIMENTAL, API might change!\n resolveNode: resolveNode,\n status: {\n currentHookName: ?string,\n currentHookEvent: ?string,\n },\n scopeByType: Map<GraphQLType, Scope>,\n|};\n\nexport type BuildExtensionQuery = {|\n $$isQuery: Symbol,\n|};\n\nexport type Scope = {\n __origin: ?string,\n [string]: mixed,\n};\n\nexport type Context = {|\n scope: Scope,\n type: string,\n [string]: mixed,\n|};\n\ntype DataGeneratorFunction = () => {};\n\nexport type ContextGraphQLObjectTypeFields = {|\n addDataGeneratorForField: (\n fieldName: string,\n fn: DataGeneratorFunction\n ) => void,\n recurseDataGeneratorsForField: (fieldName: string) => void, // @deprecated - DO NOT USE!\n Self: GraphQLNamedType,\n GraphQLObjectType: GraphQLObjectTypeConfig<*, *>,\n fieldWithHooks: FieldWithHooksFunction,\n|};\n\ntype SupportedHookTypes = {} | Build | Array<GraphQLInterfaceType>;\n\nexport type Hook<\n Type: SupportedHookTypes,\n BuildExtensions: *,\n ContextExtensions: *\n> = {\n (\n input: Type,\n build: { ...Build, ...BuildExtensions },\n context: { ...Context, ...ContextExtensions }\n ): Type,\n displayName?: string,\n provides?: Array<string>,\n before?: Array<string>,\n after?: Array<string>,\n};\n\nexport type WatchUnwatch = (triggerChange: TriggerChangeType) => void;\n\nexport type SchemaListener = (newSchema: GraphQLSchema) => void;\n\nclass SchemaBuilder extends EventEmitter {\n options: Options;\n watchers: Array<WatchUnwatch>;\n unwatchers: Array<WatchUnwatch>;\n triggerChange: ?TriggerChangeType;\n depth: number;\n hooks: {\n [string]: Array<Hook<*, *, *>>,\n };\n\n _currentPluginName: ?string;\n _generatedSchema: ?GraphQLSchema;\n _explicitSchemaListener: ?SchemaListener;\n _busy: boolean;\n _watching: boolean;\n\n constructor(options: Options) {\n super();\n\n this.options = options;\n if (!options) {\n throw new Error(\"Please pass options to SchemaBuilder\");\n }\n\n this._busy = false;\n this._watching = false;\n\n this.watchers = [];\n this.unwatchers = [];\n\n // Because hooks can nest, this keeps track of how deep we are.\n this.depth = -1;\n\n this.hooks = {\n // The build object represents the current schema build and is passed to\n // all hooks, hook the 'build' event to extend this object:\n build: [],\n\n // Inflection is used for naming resulting types/fields/args/etc - it's\n // hookable so that other plugins may extend it or override it\n inflection: [],\n\n // 'build' phase should not generate any GraphQL objects (because the\n // build object isn't finalised yet so it risks weirdness occurring); so\n // if you need to set up any global types you can do so here.\n init: [],\n\n // 'finalize' phase is called once the schema is built; typically you\n // shouldn't use this, but it's useful for interfacing with external\n // libraries that mutate an already constructed schema.\n finalize: [],\n\n // Add 'query', 'mutation' or 'subscription' types in this hook:\n GraphQLSchema: [],\n\n // When creating a GraphQLObjectType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLObjectType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLObjectType:interfaces' to add additional interfaces to this object type\n // - 'GraphQLObjectType:fields' to add additional fields to this object type (is\n // ran asynchronously and gets a reference to the final GraphQL Object as\n // `Self` in the context)\n // - 'GraphQLObjectType:fields:field' to customise an individual field from above\n // - 'GraphQLObjectType:fields:field:args' to customize the arguments to a field\n GraphQLObjectType: [],\n \"GraphQLObjectType:interfaces\": [],\n \"GraphQLObjectType:fields\": [],\n \"GraphQLObjectType:fields:field\": [],\n \"GraphQLObjectType:fields:field:args\": [],\n\n // When creating a GraphQLInputObjectType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLInputObjectType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLInputObjectType:fields' to add additional fields to this object type (is\n // ran asynchronously and gets a reference to the final GraphQL Object as\n // `Self` in the context)\n // - 'GraphQLInputObjectType:fields:field' to customise an individual field from above\n GraphQLInputObjectType: [],\n \"GraphQLInputObjectType:fields\": [],\n \"GraphQLInputObjectType:fields:field\": [],\n\n // When creating a GraphQLEnumType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLEnumType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLEnumType:values' to add additional values\n // - 'GraphQLEnumType:values:value' to change an individual value\n GraphQLEnumType: [],\n \"GraphQLEnumType:values\": [],\n \"GraphQLEnumType:values:value\": [],\n\n // When creating a GraphQLUnionType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLUnionType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLUnionType:types' to add additional types to this union\n GraphQLUnionType: [],\n \"GraphQLUnionType:types\": [],\n };\n }\n\n _setPluginName(name: ?string) {\n this._currentPluginName = name;\n }\n\n /*\n * Every hook `fn` takes three arguments:\n * - obj - the object currently being inspected\n * - build - the current build object (which contains a number of utilities and the context of the build)\n * - context - information specific to the current invocation of the hook\n *\n * The function must either return a replacement object for `obj` or `obj` itself\n */\n hook<T: *>(\n hookName: string,\n fn: Hook<T, *, *>,\n provides?: Array<string>,\n before?: Array<string>,\n after?: Array<string>\n ) {\n if (!this.hooks[hookName]) {\n throw new Error(`Sorry, '${hookName}' is not a supported hook`);\n }\n if (this._currentPluginName) {\n fn.displayName = `${this._currentPluginName}/${hookName}/${(provides &&\n provides.length &&\n provides.join(\"+\")) ||\n fn.displayName ||\n fn.name ||\n \"unnamed\"}`;\n }\n if (provides) {\n if (!fn.displayName && provides.length) {\n fn.displayName = `unknown/${hookName}/${provides[0]}`;\n }\n fn.provides = provides;\n }\n if (before) {\n fn.before = before;\n }\n if (after) {\n fn.after = after;\n }\n if (!fn.provides && !fn.before && !fn.after) {\n // No explicit dependencies - add to the end\n this.hooks[hookName].push(fn);\n } else {\n // We need to figure out where it can go, respecting all the dependencies.\n // TODO: I think there are situations in which this algorithm may result in unnecessary conflict errors; we should take a more iterative approach or find a better algorithm\n const relevantHooks = this.hooks[hookName];\n let minIndex = 0;\n let minReason = null;\n let maxIndex = relevantHooks.length;\n let maxReason = null;\n const { provides: newProvides, before: newBefore, after: newAfter } = fn;\n const describe = (hook, index) => {\n if (!hook) {\n return \"-\";\n }\n return `${hook.displayName || hook.name || \"anonymous\"} (${\n index ? `index: ${index}, ` : \"\"\n }provides: ${hook.provides ? hook.provides.join(\",\") : \"-\"}, before: ${\n hook.before ? hook.before.join(\",\") : \"-\"\n }, after: ${hook.after ? hook.after.join(\",\") : \"-\"})`;\n };\n const check = () => {\n if (minIndex > maxIndex) {\n throw new Error(\n `Cannot resolve plugin order - ${describe(\n fn\n )} cannot be before ${describe(\n maxReason,\n maxIndex\n )} and after ${describe(\n minReason,\n minIndex\n )} - please report this issue`\n );\n }\n };\n const setMin = (newMin, reason) => {\n if (newMin > minIndex) {\n minIndex = newMin;\n minReason = reason;\n check();\n }\n };\n const setMax = (newMax, reason) => {\n if (newMax < maxIndex) {\n maxIndex = newMax;\n maxReason = reason;\n check();\n }\n };\n relevantHooks.forEach((oldHook, idx) => {\n const {\n provides: oldProvides,\n before: oldBefore,\n after: oldAfter,\n } = oldHook;\n if (newProvides) {\n if (oldBefore && oldBefore.some(dep => newProvides.includes(dep))) {\n // Old says it has to come before new\n setMin(idx + 1, oldHook);\n }\n if (oldAfter && oldAfter.some(dep => newProvides.includes(dep))) {\n // Old says it has to be after new\n setMax(idx, oldHook);\n }\n }\n if (oldProvides) {\n if (newBefore && newBefore.some(dep => oldProvides.includes(dep))) {\n // New says it has to come before old\n setMax(idx, oldHook);\n }\n if (newAfter && newAfter.some(dep => oldProvides.includes(dep))) {\n // New says it has to be after old\n setMin(idx + 1, oldHook);\n }\n }\n });\n\n // We've already validated everything, so we can now insert the record.\n this.hooks[hookName].splice(maxIndex, 0, fn);\n }\n }\n\n applyHooks<T: *, Context>(\n build: { ...Build },\n hookName: string,\n input: T,\n context: Context,\n debugStr: string = \"\"\n ): T {\n if (!input) {\n throw new Error(\"applyHooks was called with falsy input\");\n }\n this.depth++;\n try {\n debug(`${INDENT.repeat(this.depth)}[${hookName}${debugStr}]: Running...`);\n\n const hooks: Array<Hook<T, *, *>> = this.hooks[hookName];\n if (!hooks) {\n throw new Error(`Sorry, '${hookName}' is not a registered hook`);\n }\n\n let newObj = input;\n for (const hook: Hook<T, *, *> of hooks) {\n this.depth++;\n try {\n const hookDisplayName = hook.displayName || hook.name || \"anonymous\";\n debug(\n `${INDENT.repeat(\n this.depth\n )}[${hookName}${debugStr}]: Executing '${hookDisplayName}'`\n );\n\n const previousHookName = build.status.currentHookName;\n const previousHookEvent = build.status.currentHookEvent;\n build.status.currentHookName = hookDisplayName;\n build.status.currentHookEvent = hookName;\n const oldObj = newObj;\n newObj = hook(newObj, build, context);\n if (hookName === \"build\") {\n /*\n * Unlike all the other hooks, the `build` hook must always use the\n * same `build` object - never returning a new object for fear of\n * causing issues to other build hooks that reference the old\n * object and don't get the new additions.\n */\n if (newObj !== oldObj) {\n // TODO:v5: forbid this\n // eslint-disable-next-line no-console\n console.warn(\n `Build hook '${hookDisplayName}' returned a new object; please use 'return build.extend(build, {...})' instead.`\n );\n // Copy everything from newObj back to oldObj\n Object.assign(oldObj, newObj);\n // Go back to the old objectect\n newObj = oldObj;\n }\n }\n build.status.currentHookName = previousHookName;\n build.status.currentHookEvent = previousHookEvent;\n\n if (!newObj) {\n throw new Error(\n `Hook '${hook.displayName ||\n hook.name ||\n \"anonymous\"}' for '${hookName}' returned falsy value '${newObj}'`\n );\n }\n debug(\n `${INDENT.repeat(\n this.depth\n )}[${hookName}${debugStr}]: '${hookDisplayName}' complete`\n );\n } finally {\n this.depth--;\n }\n }\n\n debug(`${INDENT.repeat(this.depth)}[${hookName}${debugStr}]: Complete`);\n\n return newObj;\n } finally {\n this.depth--;\n }\n }\n\n registerWatcher(listen: WatchUnwatch, unlisten: WatchUnwatch) {\n if (!listen || !unlisten) {\n throw new Error(\"You must provide both a listener and an unlistener\");\n }\n this.watchers.push(listen);\n this.unwatchers.push(unlisten);\n }\n\n createBuild(): { ...Build } {\n const initialBuild = makeNewBuild(this);\n // Inflection needs to come first, in case 'build' hooks depend on it\n initialBuild.inflection = this.applyHooks(\n initialBuild,\n \"inflection\",\n initialBuild.inflection,\n {\n scope: {},\n }\n );\n const build = this.applyHooks(initialBuild, \"build\", initialBuild, {\n scope: {},\n });\n // Bind all functions so they can be dereferenced\n bindAll(\n build,\n Object.keys(build).filter(key => typeof build[key] === \"function\")\n );\n Object.freeze(build);\n this.applyHooks(build, \"init\", {}, { scope: {} });\n return build;\n }\n\n buildSchema(): GraphQLSchema {\n if (!this._generatedSchema) {\n const build = this.createBuild();\n const schema = build.newWithHooks(\n GraphQLSchema,\n {\n directives: [...build.graphql.specifiedDirectives],\n },\n {\n __origin: `GraphQL built-in`,\n isSchema: true,\n }\n );\n this._generatedSchema = this.applyHooks(\n build,\n \"finalize\",\n schema,\n {},\n \"Finalising GraphQL schema\"\n );\n }\n if (!this._generatedSchema) {\n throw new Error(\"Schema generation failed\");\n }\n return this._generatedSchema;\n }\n\n async watchSchema(listener?: SchemaListener) {\n if (this._busy) {\n throw new Error(\"An operation is in progress\");\n }\n if (this._watching) {\n throw new Error(\n \"We're already watching this schema! Use `builder.on('schema', callback)` instead.\"\n );\n }\n try {\n this._busy = true;\n this._explicitSchemaListener = listener;\n\n // We want to ignore `triggerChange` calls that occur whilst we're setting\n // up the listeners to prevent an unnecessary double schema build.\n let ignoreChangeTriggers = true;\n\n this.triggerChange = () => {\n if (ignoreChangeTriggers) {\n return;\n }\n this._generatedSchema = null;\n // XXX: optionally debounce\n try {\n const schema = this.buildSchema();\n this.emit(\"schema\", schema);\n } catch (e) {\n // Build errors introduced while watching are ignored because it's\n // primarily used in development.\n // eslint-disable-next-line no-console\n console.error(\n \"⚠️⚠️⚠️ An error occured when building the schema on watch:\"\n );\n // eslint-disable-next-line no-console\n console.error(e);\n }\n };\n try {\n this._watching = true;\n for (const fn of this.watchers) {\n await fn(this.triggerChange);\n }\n\n // Now we're about to build the first schema, any further\n // `triggerChange` calls should be honoured.\n ignoreChangeTriggers = false;\n\n if (listener) {\n this.on(\"schema\", listener);\n }\n this.emit(\"schema\", this.buildSchema());\n } catch (e) {\n try {\n this._busy = false;\n // Abort abort!\n await this.unwatchSchema();\n } catch (e2) {\n console.error(\n `Error when unwatching schema after error during schema build: ${e}`\n );\n }\n throw e;\n }\n } finally {\n this._busy = false;\n }\n }\n\n async unwatchSchema() {\n if (this._busy) {\n throw new Error(\"An operation is in progress\");\n }\n if (!this._watching) {\n throw new Error(\"We're not watching this schema!\");\n }\n this._busy = true;\n try {\n const listener = this._explicitSchemaListener;\n this._explicitSchemaListener = null;\n if (listener) {\n this.removeListener(\"schema\", listener);\n }\n if (this.triggerChange) {\n for (const fn of this.unwatchers) {\n await fn(this.triggerChange);\n }\n }\n this.triggerChange = null;\n this._watching = false;\n } finally {\n this._busy = false;\n }\n }\n}\n\nexport default SchemaBuilder;\n"],"file":"SchemaBuilder.js"}
1
+ {"version":3,"sources":["../src/SchemaBuilder.js"],"names":["GraphQLSchema","graphql","debug","INDENT","SchemaBuilder","EventEmitter","constructor","options","Error","_busy","_watching","watchers","unwatchers","depth","hooks","build","inflection","init","finalize","GraphQLObjectType","GraphQLInputObjectType","GraphQLEnumType","GraphQLUnionType","GraphQLInterfaceType","_setPluginName","name","_currentPluginName","hook","hookName","fn","provides","before","after","displayName","length","join","push","relevantHooks","minIndex","minReason","maxIndex","maxReason","newProvides","newBefore","newAfter","describe","index","check","setMin","newMin","reason","setMax","newMax","forEach","oldHook","idx","oldProvides","oldBefore","oldAfter","some","dep","includes","splice","applyHooks","input","context","debugStr","repeat","newObj","hookDisplayName","previousHookName","status","currentHookName","previousHookEvent","currentHookEvent","oldObj","console","warn","Object","assign","registerWatcher","listen","unlisten","createBuild","initialBuild","scope","keys","filter","key","freeze","buildSchema","_generatedSchema","schema","newWithHooks","directives","specifiedDirectives","__origin","isSchema","hookedSchema","errors","validateSchema","map","e","message","replace","watchSchema","listener","_explicitSchemaListener","ignoreChangeTriggers","triggerChange","emit","error","on","unwatchSchema","e2","removeListener"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAOA;;;;;;;;AAWA,MAAM;AAAEA,EAAAA;AAAF,IAAoBC,OAA1B;AAEA,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AAL,GAAa,IAAb;;AACA,QAAI;AACF,YAAMiG,QAAQ,GAAG,KAAKC,uBAAtB;AACA,WAAKA,uBAAL,GAA+B,IAA/B;;AACA,UAAID,QAAJ,EAAc;AACZ,aAAKS,cAAL,CAAoB,QAApB,EAA8BT,QAA9B;AACD;;AACD,UAAI,KAAKG,aAAT,EAAwB;AACtB,aAAK,MAAMhF,EAAX,IAAiB,KAAKjB,UAAtB,EAAkC;AAChC,gBAAMiB,EAAE,CAAC,KAAKgF,aAAN,CAAR;AACD;AACF;;AACD,WAAKA,aAAL,GAAqB,IAArB;AACA,WAAKnG,SAAL,GAAiB,KAAjB;AACD,KAbD,SAaU;AACR,WAAKD,KAAL,GAAa,KAAb;AACD;AACF;;AAhesC;;eAme1BL,a","sourcesContent":["// @flow\nimport debugFactory from \"debug\";\nimport makeNewBuild from \"./makeNewBuild\";\nimport { bindAll } from \"./utils\";\nimport * as graphql from \"graphql\";\nimport type {\n GraphQLType,\n GraphQLNamedType,\n GraphQLInterfaceType,\n GraphQLObjectTypeConfig,\n} from \"graphql\";\nimport EventEmitter from \"events\";\n// TODO: when we move to TypeScript, change this to:\n// import { EventEmitter } from \"events\";\nimport type {\n simplifyParsedResolveInfoFragmentWithType,\n parseResolveInfo,\n} from \"graphql-parse-resolve-info\";\nimport type { GraphQLResolveInfo } from \"graphql/type/definition\";\nimport type resolveNode from \"./resolveNode\";\n\nimport type { FieldWithHooksFunction } from \"./makeNewBuild\";\nconst { GraphQLSchema } = graphql;\n\nconst debug = debugFactory(\"graphile-builder\");\n\nconst INDENT = \" \";\n\nexport type Options = {\n [string]: mixed,\n};\n\nexport type Plugin = (\n builder: SchemaBuilder,\n options: Options\n) => Promise<void> | void;\n\ntype TriggerChangeType = () => void;\n\nexport type DataForType = {\n [string]: Array<mixed>,\n};\n\nexport type Build = {|\n graphileBuildVersion: string,\n graphql: *,\n parseResolveInfo: parseResolveInfo,\n simplifyParsedResolveInfoFragmentWithType: simplifyParsedResolveInfoFragmentWithType,\n // DEPRECATED: getAliasFromResolveInfo: (resolveInfo: GraphQLResolveInfo) => string,\n getSafeAliasFromResolveInfo: (resolveInfo: GraphQLResolveInfo) => string,\n getSafeAliasFromAlias: (alias: string) => string,\n resolveAlias(\n data: {},\n _args: mixed,\n _context: mixed,\n resolveInfo: GraphQLResolveInfo\n ): string,\n addType(type: GraphQLNamedType, origin?: ?string): void,\n getTypeByName(typeName: string): ?GraphQLType,\n extend<Obj1: *, Obj2: *>(base: Obj1, extra: Obj2, hint?: string): Obj1 & Obj2,\n newWithHooks<T: GraphQLNamedType | GraphQLSchema, ConfigType: *>(\n Class<T>,\n spec: ConfigType,\n scope: Scope,\n performNonEmptyFieldsCheck?: boolean\n ): ?T,\n fieldDataGeneratorsByType: Map<*, *>, // @deprecated - use fieldDataGeneratorsByFieldNameByType instead\n fieldDataGeneratorsByFieldNameByType: Map<*, *>,\n fieldArgDataGeneratorsByFieldNameByType: Map<*, *>,\n inflection: {\n // eslint-disable-next-line flowtype/no-weak-types\n [string]: (...args: Array<any>) => string,\n },\n wrapDescription: (\n description: string,\n position: \"root\" | \"type\" | \"field\" | \"arg\"\n ) => string,\n swallowError: (e: Error) => void,\n // resolveNode: EXPERIMENTAL, API might change!\n resolveNode: resolveNode,\n status: {\n currentHookName: ?string,\n currentHookEvent: ?string,\n },\n scopeByType: Map<GraphQLType, Scope>,\n|};\n\nexport type BuildExtensionQuery = {|\n $$isQuery: Symbol,\n|};\n\nexport type Scope = {\n __origin: ?string,\n [string]: mixed,\n};\n\nexport type Context = {|\n scope: Scope,\n type: string,\n [string]: mixed,\n|};\n\ntype DataGeneratorFunction = () => {};\n\nexport type ContextGraphQLObjectTypeFields = {|\n addDataGeneratorForField: (\n fieldName: string,\n fn: DataGeneratorFunction\n ) => void,\n recurseDataGeneratorsForField: (fieldName: string) => void, // @deprecated - DO NOT USE!\n Self: GraphQLNamedType,\n GraphQLObjectType: GraphQLObjectTypeConfig<*, *>,\n fieldWithHooks: FieldWithHooksFunction,\n|};\n\ntype SupportedHookTypes = {} | Build | Array<GraphQLInterfaceType>;\n\nexport type Hook<\n Type: SupportedHookTypes,\n BuildExtensions: *,\n ContextExtensions: *\n> = {\n (\n input: Type,\n build: { ...Build, ...BuildExtensions },\n context: { ...Context, ...ContextExtensions }\n ): Type,\n displayName?: string,\n provides?: Array<string>,\n before?: Array<string>,\n after?: Array<string>,\n};\n\nexport type WatchUnwatch = (triggerChange: TriggerChangeType) => void;\n\nexport type SchemaListener = (newSchema: GraphQLSchema) => void;\n\nclass SchemaBuilder extends EventEmitter {\n options: Options;\n watchers: Array<WatchUnwatch>;\n unwatchers: Array<WatchUnwatch>;\n triggerChange: ?TriggerChangeType;\n depth: number;\n hooks: {\n [string]: Array<Hook<*, *, *>>,\n };\n\n _currentPluginName: ?string;\n _generatedSchema: ?GraphQLSchema;\n _explicitSchemaListener: ?SchemaListener;\n _busy: boolean;\n _watching: boolean;\n\n constructor(options: Options) {\n super();\n\n this.options = options;\n if (!options) {\n throw new Error(\"Please pass options to SchemaBuilder\");\n }\n\n this._busy = false;\n this._watching = false;\n\n this.watchers = [];\n this.unwatchers = [];\n\n // Because hooks can nest, this keeps track of how deep we are.\n this.depth = -1;\n\n this.hooks = {\n // The build object represents the current schema build and is passed to\n // all hooks, hook the 'build' event to extend this object:\n build: [],\n\n // Inflection is used for naming resulting types/fields/args/etc - it's\n // hookable so that other plugins may extend it or override it\n inflection: [],\n\n // 'build' phase should not generate any GraphQL objects (because the\n // build object isn't finalised yet so it risks weirdness occurring); so\n // if you need to set up any global types you can do so here.\n init: [],\n\n // 'finalize' phase is called once the schema is built; typically you\n // shouldn't use this, but it's useful for interfacing with external\n // libraries that mutate an already constructed schema.\n finalize: [],\n\n // Add 'query', 'mutation' or 'subscription' types in this hook:\n GraphQLSchema: [],\n\n // When creating a GraphQLObjectType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLObjectType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLObjectType:interfaces' to add additional interfaces to this object type\n // - 'GraphQLObjectType:fields' to add additional fields to this object type (is\n // ran asynchronously and gets a reference to the final GraphQL Object as\n // `Self` in the context)\n // - 'GraphQLObjectType:fields:field' to customise an individual field from above\n // - 'GraphQLObjectType:fields:field:args' to customize the arguments to a field\n GraphQLObjectType: [],\n \"GraphQLObjectType:interfaces\": [],\n \"GraphQLObjectType:fields\": [],\n \"GraphQLObjectType:fields:field\": [],\n \"GraphQLObjectType:fields:field:args\": [],\n\n // When creating a GraphQLInputObjectType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLInputObjectType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLInputObjectType:fields' to add additional fields to this object type (is\n // ran asynchronously and gets a reference to the final GraphQL Object as\n // `Self` in the context)\n // - 'GraphQLInputObjectType:fields:field' to customise an individual field from above\n GraphQLInputObjectType: [],\n \"GraphQLInputObjectType:fields\": [],\n \"GraphQLInputObjectType:fields:field\": [],\n\n // When creating a GraphQLEnumType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLEnumType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLEnumType:values' to add additional values\n // - 'GraphQLEnumType:values:value' to change an individual value\n GraphQLEnumType: [],\n \"GraphQLEnumType:values\": [],\n \"GraphQLEnumType:values:value\": [],\n\n // When creating a GraphQLUnionType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLUnionType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLUnionType:types' to add additional types to this union\n GraphQLUnionType: [],\n \"GraphQLUnionType:types\": [],\n\n // When creating a GraphQLInterfaceType via `newWithHooks`, we'll\n // execute, the following hooks:\n // - 'GraphQLInterfaceType' to add any root-level attributes, e.g. add a description\n // - 'GraphQLInterfaceType:fields' to add additional fields to this interface type (is\n // ran asynchronously and gets a reference to the final GraphQL Interface as\n // `Self` in the context)\n // - 'GraphQLInterfaceType:fields:field' to customise an individual field from above\n // - 'GraphQLInterfaceType:fields:field:args' to customize the arguments to a field\n GraphQLInterfaceType: [],\n \"GraphQLInterfaceType:fields\": [],\n \"GraphQLInterfaceType:fields:field\": [],\n \"GraphQLInterfaceType:fields:field:args\": [],\n };\n }\n\n _setPluginName(name: ?string) {\n this._currentPluginName = name;\n }\n\n /*\n * Every hook `fn` takes three arguments:\n * - obj - the object currently being inspected\n * - build - the current build object (which contains a number of utilities and the context of the build)\n * - context - information specific to the current invocation of the hook\n *\n * The function must either return a replacement object for `obj` or `obj` itself\n */\n hook<T: *>(\n hookName: string,\n fn: Hook<T, *, *>,\n provides?: Array<string>,\n before?: Array<string>,\n after?: Array<string>\n ) {\n if (!this.hooks[hookName]) {\n throw new Error(`Sorry, '${hookName}' is not a supported hook`);\n }\n if (this._currentPluginName) {\n fn.displayName = `${this._currentPluginName}/${hookName}/${\n (provides && provides.length && provides.join(\"+\")) ||\n fn.displayName ||\n fn.name ||\n \"unnamed\"\n }`;\n }\n if (provides) {\n if (!fn.displayName && provides.length) {\n fn.displayName = `unknown/${hookName}/${provides[0]}`;\n }\n fn.provides = provides;\n }\n if (before) {\n fn.before = before;\n }\n if (after) {\n fn.after = after;\n }\n if (!fn.provides && !fn.before && !fn.after) {\n // No explicit dependencies - add to the end\n this.hooks[hookName].push(fn);\n } else {\n // We need to figure out where it can go, respecting all the dependencies.\n // TODO: I think there are situations in which this algorithm may result in unnecessary conflict errors; we should take a more iterative approach or find a better algorithm\n const relevantHooks = this.hooks[hookName];\n let minIndex = 0;\n let minReason = null;\n let maxIndex = relevantHooks.length;\n let maxReason = null;\n const { provides: newProvides, before: newBefore, after: newAfter } = fn;\n const describe = (hook, index) => {\n if (!hook) {\n return \"-\";\n }\n return `${hook.displayName || hook.name || \"anonymous\"} (${\n index ? `index: ${index}, ` : \"\"\n }provides: ${hook.provides ? hook.provides.join(\",\") : \"-\"}, before: ${\n hook.before ? hook.before.join(\",\") : \"-\"\n }, after: ${hook.after ? hook.after.join(\",\") : \"-\"})`;\n };\n const check = () => {\n if (minIndex > maxIndex) {\n throw new Error(\n `Cannot resolve plugin order - ${describe(\n fn\n )} cannot be before ${describe(\n maxReason,\n maxIndex\n )} and after ${describe(\n minReason,\n minIndex\n )} - please report this issue`\n );\n }\n };\n const setMin = (newMin, reason) => {\n if (newMin > minIndex) {\n minIndex = newMin;\n minReason = reason;\n check();\n }\n };\n const setMax = (newMax, reason) => {\n if (newMax < maxIndex) {\n maxIndex = newMax;\n maxReason = reason;\n check();\n }\n };\n relevantHooks.forEach((oldHook, idx) => {\n const {\n provides: oldProvides,\n before: oldBefore,\n after: oldAfter,\n } = oldHook;\n if (newProvides) {\n if (oldBefore && oldBefore.some(dep => newProvides.includes(dep))) {\n // Old says it has to come before new\n setMin(idx + 1, oldHook);\n }\n if (oldAfter && oldAfter.some(dep => newProvides.includes(dep))) {\n // Old says it has to be after new\n setMax(idx, oldHook);\n }\n }\n if (oldProvides) {\n if (newBefore && newBefore.some(dep => oldProvides.includes(dep))) {\n // New says it has to come before old\n setMax(idx, oldHook);\n }\n if (newAfter && newAfter.some(dep => oldProvides.includes(dep))) {\n // New says it has to be after old\n setMin(idx + 1, oldHook);\n }\n }\n });\n\n // We've already validated everything, so we can now insert the record.\n this.hooks[hookName].splice(maxIndex, 0, fn);\n }\n }\n\n applyHooks<T: *, Context>(\n build: { ...Build },\n hookName: string,\n input: T,\n context: Context,\n debugStr: string = \"\"\n ): T {\n if (!input) {\n throw new Error(\"applyHooks was called with falsy input\");\n }\n this.depth++;\n try {\n debug(`${INDENT.repeat(this.depth)}[${hookName}${debugStr}]: Running...`);\n\n const hooks: Array<Hook<T, *, *>> = this.hooks[hookName];\n if (!hooks) {\n throw new Error(`Sorry, '${hookName}' is not a registered hook`);\n }\n\n let newObj = input;\n for (const hook: Hook<T, *, *> of hooks) {\n this.depth++;\n try {\n const hookDisplayName = hook.displayName || hook.name || \"anonymous\";\n debug(\n `${INDENT.repeat(\n this.depth\n )}[${hookName}${debugStr}]: Executing '${hookDisplayName}'`\n );\n\n const previousHookName = build.status.currentHookName;\n const previousHookEvent = build.status.currentHookEvent;\n build.status.currentHookName = hookDisplayName;\n build.status.currentHookEvent = hookName;\n const oldObj = newObj;\n newObj = hook(newObj, build, context);\n if (hookName === \"build\") {\n /*\n * Unlike all the other hooks, the `build` hook must always use the\n * same `build` object - never returning a new object for fear of\n * causing issues to other build hooks that reference the old\n * object and don't get the new additions.\n */\n if (newObj !== oldObj) {\n // TODO:v5: forbid this\n // eslint-disable-next-line no-console\n console.warn(\n `Build hook '${hookDisplayName}' returned a new object; please use 'return build.extend(build, {...})' instead.`\n );\n // Copy everything from newObj back to oldObj\n Object.assign(oldObj, newObj);\n // Go back to the old objectect\n newObj = oldObj;\n }\n }\n build.status.currentHookName = previousHookName;\n build.status.currentHookEvent = previousHookEvent;\n\n if (!newObj) {\n throw new Error(\n `Hook '${\n hook.displayName || hook.name || \"anonymous\"\n }' for '${hookName}' returned falsy value '${newObj}'`\n );\n }\n debug(\n `${INDENT.repeat(\n this.depth\n )}[${hookName}${debugStr}]: '${hookDisplayName}' complete`\n );\n } finally {\n this.depth--;\n }\n }\n\n debug(`${INDENT.repeat(this.depth)}[${hookName}${debugStr}]: Complete`);\n\n return newObj;\n } finally {\n this.depth--;\n }\n }\n\n registerWatcher(listen: WatchUnwatch, unlisten: WatchUnwatch) {\n if (!listen || !unlisten) {\n throw new Error(\"You must provide both a listener and an unlistener\");\n }\n this.watchers.push(listen);\n this.unwatchers.push(unlisten);\n }\n\n createBuild(): { ...Build } {\n const initialBuild = makeNewBuild(this);\n // Inflection needs to come first, in case 'build' hooks depend on it\n initialBuild.inflection = this.applyHooks(\n initialBuild,\n \"inflection\",\n initialBuild.inflection,\n {\n scope: {},\n }\n );\n const build = this.applyHooks(initialBuild, \"build\", initialBuild, {\n scope: {},\n });\n // Bind all functions so they can be dereferenced\n bindAll(\n build,\n Object.keys(build).filter(key => typeof build[key] === \"function\")\n );\n Object.freeze(build);\n this.applyHooks(build, \"init\", {}, { scope: {} });\n return build;\n }\n\n buildSchema(): GraphQLSchema {\n if (!this._generatedSchema) {\n const build = this.createBuild();\n const schema = build.newWithHooks(\n GraphQLSchema,\n {\n directives: [...build.graphql.specifiedDirectives],\n },\n {\n __origin: `GraphQL built-in`,\n isSchema: true,\n }\n );\n const hookedSchema = this.applyHooks(\n build,\n \"finalize\",\n schema,\n {},\n \"Finalising GraphQL schema\"\n );\n const errors = build.graphql.validateSchema(hookedSchema);\n if (errors && errors.length) {\n throw new Error(\n \"GraphQL schema is invalid:\\n\" +\n errors.map(e => `- ` + e.message.replace(/\\n/g, \"\\n \")).join(\"\\n\")\n );\n }\n this._generatedSchema = hookedSchema;\n }\n if (!this._generatedSchema) {\n throw new Error(\"Schema generation failed\");\n }\n return this._generatedSchema;\n }\n\n async watchSchema(listener?: SchemaListener) {\n if (this._busy) {\n throw new Error(\"An operation is in progress\");\n }\n if (this._watching) {\n throw new Error(\n \"We're already watching this schema! Use `builder.on('schema', callback)` instead.\"\n );\n }\n try {\n this._busy = true;\n this._explicitSchemaListener = listener;\n\n // We want to ignore `triggerChange` calls that occur whilst we're setting\n // up the listeners to prevent an unnecessary double schema build.\n let ignoreChangeTriggers = true;\n\n this.triggerChange = () => {\n if (ignoreChangeTriggers) {\n return;\n }\n this._generatedSchema = null;\n // XXX: optionally debounce\n try {\n const schema = this.buildSchema();\n this.emit(\"schema\", schema);\n } catch (e) {\n // Build errors introduced while watching are ignored because it's\n // primarily used in development.\n // eslint-disable-next-line no-console\n console.error(\n \"⚠️⚠️⚠️ An error occured when building the schema on watch:\"\n );\n // eslint-disable-next-line no-console\n console.error(e);\n }\n };\n try {\n this._watching = true;\n for (const fn of this.watchers) {\n await fn(this.triggerChange);\n }\n\n // Now we're about to build the first schema, any further\n // `triggerChange` calls should be honoured.\n ignoreChangeTriggers = false;\n\n if (listener) {\n this.on(\"schema\", listener);\n }\n this.emit(\"schema\", this.buildSchema());\n } catch (e) {\n try {\n this._busy = false;\n // Abort abort!\n await this.unwatchSchema();\n } catch (e2) {\n console.error(\n `Error when unwatching schema after error during schema build: ${e}`\n );\n }\n throw e;\n }\n } finally {\n this._busy = false;\n }\n }\n\n async unwatchSchema() {\n if (this._busy) {\n throw new Error(\"An operation is in progress\");\n }\n if (!this._watching) {\n throw new Error(\"We're not watching this schema!\");\n }\n this._busy = true;\n try {\n const listener = this._explicitSchemaListener;\n this._explicitSchemaListener = null;\n if (listener) {\n this.removeListener(\"schema\", listener);\n }\n if (this.triggerChange) {\n for (const fn of this.unwatchers) {\n await fn(this.triggerChange);\n }\n }\n this.triggerChange = null;\n this._watching = false;\n } finally {\n this._busy = false;\n }\n }\n}\n\nexport default SchemaBuilder;\n"],"file":"SchemaBuilder.js"}
@@ -180,6 +180,6 @@ const buildSchema = async (plugins, options = {}) => {
180
180
  };
181
181
 
182
182
  exports.buildSchema = buildSchema;
183
- const defaultPlugins = [_plugins.SwallowErrorsPlugin, _plugins.StandardTypesPlugin, _plugins.NodePlugin, _plugins.QueryPlugin, _plugins.MutationPlugin, _plugins.SubscriptionPlugin, _plugins.ClientMutationIdDescriptionPlugin, _plugins.MutationPayloadQueryPlugin, _plugins.AddQueriesToSubscriptionsPlugin];
183
+ const defaultPlugins = [_plugins.SwallowErrorsPlugin, _plugins.StandardTypesPlugin, _plugins.NodePlugin, _plugins.QueryPlugin, _plugins.MutationPlugin, _plugins.SubscriptionPlugin, _plugins.ClientMutationIdDescriptionPlugin, _plugins.MutationPayloadQueryPlugin, _plugins.AddQueriesToSubscriptionsPlugin, _plugins.TrimEmptyDescriptionsPlugin];
184
184
  exports.defaultPlugins = defaultPlugins;
185
185
  //# sourceMappingURL=index.js.map
@@ -12,6 +12,7 @@ import {
12
12
  ClientMutationIdDescriptionPlugin,
13
13
  MutationPayloadQueryPlugin,
14
14
  AddQueriesToSubscriptionsPlugin,
15
+ TrimEmptyDescriptionsPlugin,
15
16
  } from "./plugins";
16
17
  import resolveNode from "./resolveNode";
17
18
  import type { GraphQLSchema } from "graphql";
@@ -85,6 +86,7 @@ export const defaultPlugins: Array<Plugin> = [
85
86
  ClientMutationIdDescriptionPlugin,
86
87
  MutationPayloadQueryPlugin,
87
88
  AddQueriesToSubscriptionsPlugin,
89
+ TrimEmptyDescriptionsPlugin,
88
90
  ];
89
91
 
90
92
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["getBuilder","plugins","options","builder","SchemaBuilder","i","l","length","plugin","Error","util","inspect","_setPluginName","displayName","name","buildSchema","defaultPlugins","SwallowErrorsPlugin","StandardTypesPlugin","NodePlugin","QueryPlugin","MutationPlugin","SubscriptionPlugin","ClientMutationIdDescriptionPlugin","MutationPayloadQueryPlugin","AddQueriesToSubscriptionsPlugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AAWA;;AAKA;;AAyBA;;;;AAEO,MAAMA,UAAU,GAAG,OACxBC,OADwB,EAExBC,OAAgB,GAAG,EAFK,KAGG;AAC3B,QAAMC,OAAO,GAAG,IAAIC,sBAAJ,CAAkBF,OAAlB,CAAhB;;AACA,OAAK,IAAIG,CAAC,GAAG,CAAR,EAAWC,CAAC,GAAGL,OAAO,CAACM,MAA5B,EAAoCF,CAAC,GAAGC,CAAxC,EAA2CD,CAAC,EAA5C,EAAgD;AAC9C,UAAMG,MAAM,GAAGP,OAAO,CAACI,CAAD,CAAtB;;AACA,QAAI,OAAOG,MAAP,KAAkB,UAAtB,EAAkC;AAChC,YAAM,IAAIC,KAAJ,CACH,uFAAsFJ,CAAE,KAAIK,cAAKC,OAAL,CAC3FH,MAD2F,CAE3F,EAHE,CAAN;AAKD,KAR6C,CAS9C;;;AACAL,IAAAA,OAAO,CAACS,cAAR,CAAuBJ,MAAM,CAACK,WAAP,IAAsBL,MAAM,CAACM,IAApD;;AACA,UAAMN,MAAM,CAACL,OAAD,EAAUD,OAAV,CAAZ;;AACAC,IAAAA,OAAO,CAACS,cAAR,CAAuB,IAAvB;AACD;;AACD,SAAOT,OAAP;AACD,CApBM;;;;AAsBA,MAAMY,WAAW,GAAG,OACzBd,OADyB,EAEzBC,OAAgB,GAAG,EAFM,KAGE;AAC3B,QAAMC,OAAsB,GAAG,MAAMH,UAAU,CAACC,OAAD,EAAUC,OAAV,CAA/C;AACA,SAAOC,OAAO,CAACY,WAAR,EAAP;AACD,CANM;;;AAQA,MAAMC,cAA6B,GAAG,CAC3CC,4BAD2C,EAE3CC,4BAF2C,EAG3CC,mBAH2C,EAI3CC,oBAJ2C,EAK3CC,uBAL2C,EAM3CC,2BAN2C,EAO3CC,0CAP2C,EAQ3CC,mCAR2C,EAS3CC,wCAT2C,CAAtC","sourcesContent":["// @flow\n\nimport util from \"util\";\nimport SchemaBuilder from \"./SchemaBuilder\";\nimport {\n SwallowErrorsPlugin,\n StandardTypesPlugin,\n NodePlugin,\n QueryPlugin,\n MutationPlugin,\n SubscriptionPlugin,\n ClientMutationIdDescriptionPlugin,\n MutationPayloadQueryPlugin,\n AddQueriesToSubscriptionsPlugin,\n} from \"./plugins\";\nimport resolveNode from \"./resolveNode\";\nimport type { GraphQLSchema } from \"graphql\";\n\nimport type { Plugin, Options } from \"./SchemaBuilder\";\n\nexport {\n constantCaseAll,\n formatInsideUnderscores,\n upperFirst,\n camelCase,\n constantCase,\n upperCamelCase,\n pluralize,\n singularize,\n} from \"./utils\";\n\nexport type { SchemaBuilder };\n\nexport type {\n Plugin,\n Options,\n Build,\n BuildExtensionQuery,\n Scope,\n Context,\n Hook,\n WatchUnwatch,\n SchemaListener,\n} from \"./SchemaBuilder\";\n\nexport { LiveSource, LiveProvider, LiveMonitor, LiveCoordinator } from \"./Live\";\n\nexport const getBuilder = async (\n plugins: Array<Plugin>,\n options: Options = {}\n): Promise<SchemaBuilder> => {\n const builder = new SchemaBuilder(options);\n for (let i = 0, l = plugins.length; i < l; i++) {\n const plugin = plugins[i];\n if (typeof plugin !== \"function\") {\n throw new Error(\n `Expected a list of plugin functions, instead list contained a non-function at index ${i}: ${util.inspect(\n plugin\n )}`\n );\n }\n // $FlowFixMe: displayName\n builder._setPluginName(plugin.displayName || plugin.name);\n await plugin(builder, options);\n builder._setPluginName(null);\n }\n return builder;\n};\n\nexport const buildSchema = async (\n plugins: Array<Plugin>,\n options: Options = {}\n): Promise<GraphQLSchema> => {\n const builder: SchemaBuilder = await getBuilder(plugins, options);\n return builder.buildSchema();\n};\n\nexport const defaultPlugins: Array<Plugin> = [\n SwallowErrorsPlugin,\n StandardTypesPlugin,\n NodePlugin,\n QueryPlugin,\n MutationPlugin,\n SubscriptionPlugin,\n ClientMutationIdDescriptionPlugin,\n MutationPayloadQueryPlugin,\n AddQueriesToSubscriptionsPlugin,\n];\n\nexport {\n SwallowErrorsPlugin,\n StandardTypesPlugin,\n NodePlugin,\n QueryPlugin,\n MutationPlugin,\n SubscriptionPlugin,\n ClientMutationIdDescriptionPlugin,\n MutationPayloadQueryPlugin,\n AddQueriesToSubscriptionsPlugin,\n // resolveNode: EXPERIMENTAL, API might change!\n resolveNode,\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["getBuilder","plugins","options","builder","SchemaBuilder","i","l","length","plugin","Error","util","inspect","_setPluginName","displayName","name","buildSchema","defaultPlugins","SwallowErrorsPlugin","StandardTypesPlugin","NodePlugin","QueryPlugin","MutationPlugin","SubscriptionPlugin","ClientMutationIdDescriptionPlugin","MutationPayloadQueryPlugin","AddQueriesToSubscriptionsPlugin","TrimEmptyDescriptionsPlugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AAYA;;AAKA;;AAyBA;;;;AAEO,MAAMA,UAAU,GAAG,OACxBC,OADwB,EAExBC,OAAgB,GAAG,EAFK,KAGG;AAC3B,QAAMC,OAAO,GAAG,IAAIC,sBAAJ,CAAkBF,OAAlB,CAAhB;;AACA,OAAK,IAAIG,CAAC,GAAG,CAAR,EAAWC,CAAC,GAAGL,OAAO,CAACM,MAA5B,EAAoCF,CAAC,GAAGC,CAAxC,EAA2CD,CAAC,EAA5C,EAAgD;AAC9C,UAAMG,MAAM,GAAGP,OAAO,CAACI,CAAD,CAAtB;;AACA,QAAI,OAAOG,MAAP,KAAkB,UAAtB,EAAkC;AAChC,YAAM,IAAIC,KAAJ,CACH,uFAAsFJ,CAAE,KAAIK,cAAKC,OAAL,CAC3FH,MAD2F,CAE3F,EAHE,CAAN;AAKD,KAR6C,CAS9C;;;AACAL,IAAAA,OAAO,CAACS,cAAR,CAAuBJ,MAAM,CAACK,WAAP,IAAsBL,MAAM,CAACM,IAApD;;AACA,UAAMN,MAAM,CAACL,OAAD,EAAUD,OAAV,CAAZ;;AACAC,IAAAA,OAAO,CAACS,cAAR,CAAuB,IAAvB;AACD;;AACD,SAAOT,OAAP;AACD,CApBM;;;;AAsBA,MAAMY,WAAW,GAAG,OACzBd,OADyB,EAEzBC,OAAgB,GAAG,EAFM,KAGE;AAC3B,QAAMC,OAAsB,GAAG,MAAMH,UAAU,CAACC,OAAD,EAAUC,OAAV,CAA/C;AACA,SAAOC,OAAO,CAACY,WAAR,EAAP;AACD,CANM;;;AAQA,MAAMC,cAA6B,GAAG,CAC3CC,4BAD2C,EAE3CC,4BAF2C,EAG3CC,mBAH2C,EAI3CC,oBAJ2C,EAK3CC,uBAL2C,EAM3CC,2BAN2C,EAO3CC,0CAP2C,EAQ3CC,mCAR2C,EAS3CC,wCAT2C,EAU3CC,oCAV2C,CAAtC","sourcesContent":["// @flow\n\nimport util from \"util\";\nimport SchemaBuilder from \"./SchemaBuilder\";\nimport {\n SwallowErrorsPlugin,\n StandardTypesPlugin,\n NodePlugin,\n QueryPlugin,\n MutationPlugin,\n SubscriptionPlugin,\n ClientMutationIdDescriptionPlugin,\n MutationPayloadQueryPlugin,\n AddQueriesToSubscriptionsPlugin,\n TrimEmptyDescriptionsPlugin,\n} from \"./plugins\";\nimport resolveNode from \"./resolveNode\";\nimport type { GraphQLSchema } from \"graphql\";\n\nimport type { Plugin, Options } from \"./SchemaBuilder\";\n\nexport {\n constantCaseAll,\n formatInsideUnderscores,\n upperFirst,\n camelCase,\n constantCase,\n upperCamelCase,\n pluralize,\n singularize,\n} from \"./utils\";\n\nexport type { SchemaBuilder };\n\nexport type {\n Plugin,\n Options,\n Build,\n BuildExtensionQuery,\n Scope,\n Context,\n Hook,\n WatchUnwatch,\n SchemaListener,\n} from \"./SchemaBuilder\";\n\nexport { LiveSource, LiveProvider, LiveMonitor, LiveCoordinator } from \"./Live\";\n\nexport const getBuilder = async (\n plugins: Array<Plugin>,\n options: Options = {}\n): Promise<SchemaBuilder> => {\n const builder = new SchemaBuilder(options);\n for (let i = 0, l = plugins.length; i < l; i++) {\n const plugin = plugins[i];\n if (typeof plugin !== \"function\") {\n throw new Error(\n `Expected a list of plugin functions, instead list contained a non-function at index ${i}: ${util.inspect(\n plugin\n )}`\n );\n }\n // $FlowFixMe: displayName\n builder._setPluginName(plugin.displayName || plugin.name);\n await plugin(builder, options);\n builder._setPluginName(null);\n }\n return builder;\n};\n\nexport const buildSchema = async (\n plugins: Array<Plugin>,\n options: Options = {}\n): Promise<GraphQLSchema> => {\n const builder: SchemaBuilder = await getBuilder(plugins, options);\n return builder.buildSchema();\n};\n\nexport const defaultPlugins: Array<Plugin> = [\n SwallowErrorsPlugin,\n StandardTypesPlugin,\n NodePlugin,\n QueryPlugin,\n MutationPlugin,\n SubscriptionPlugin,\n ClientMutationIdDescriptionPlugin,\n MutationPayloadQueryPlugin,\n AddQueriesToSubscriptionsPlugin,\n TrimEmptyDescriptionsPlugin,\n];\n\nexport {\n SwallowErrorsPlugin,\n StandardTypesPlugin,\n NodePlugin,\n QueryPlugin,\n MutationPlugin,\n SubscriptionPlugin,\n ClientMutationIdDescriptionPlugin,\n MutationPayloadQueryPlugin,\n AddQueriesToSubscriptionsPlugin,\n // resolveNode: EXPERIMENTAL, API might change!\n resolveNode,\n};\n"],"file":"index.js"}