@graphql-mesh/fusion-runtime 1.1.0 → 1.2.0-alpha-cb5e4f3ee67b8ef054f1fcf581125aaa3019f6bb

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # @graphql-mesh/fusion-runtime
2
2
 
3
+ ## 1.2.0-alpha-cb5e4f3ee67b8ef054f1fcf581125aaa3019f6bb
4
+ ### Minor Changes
5
+
6
+
7
+
8
+ - [#1458](https://github.com/graphql-hive/gateway/pull/1458) [`cb5e4f3`](https://github.com/graphql-hive/gateway/commit/cb5e4f3ee67b8ef054f1fcf581125aaa3019f6bb) Thanks [@ardatan](https://github.com/ardatan)! - New directive `@pubsubPublish` to publish the payload to the pubsub engine directly
9
+
10
+
11
+ ```graphql
12
+ extend schema
13
+ @link(
14
+ url: "https://specs.apollo.dev/federation/v2.6"
15
+ import: ["@key", "@composeDirective"]
16
+ )
17
+ @link(
18
+ url: "https://the-guild.dev/mesh/v1.0"
19
+ import: ["@pubsubOperation", "@pubsubPublish"]
20
+ )
21
+ @composeDirective(name: "@pubsubOperation")
22
+ @composeDirective(name: "@pubsubPublish")
23
+
24
+ directive @pubsubOperation(
25
+ pubsubTopic: String!
26
+ filterBy: String
27
+ result: String
28
+ ) on FIELD_DEFINITION
29
+
30
+ directive @pubsubPublish(pubsubTopic: String!) on FIELD_DEFINITION
31
+
32
+ type Query {
33
+ hello: String!
34
+ }
35
+ type Product @key(fields: "id") {
36
+ id: ID!
37
+ name: String!
38
+ price: Float!
39
+ }
40
+
41
+ type Mutation {
42
+ createProduct(name: String!, price: Float!): Product!
43
+ @pubsubPublish(pubsubTopic: "new_product")
44
+ }
45
+
46
+ type Subscription {
47
+ newProductSubgraph: Product!
48
+ @pubsubOperation(pubsubTopic: "new_product")
49
+ }
50
+ ```
51
+
3
52
  ## 1.1.0
4
53
  ### Minor Changes
5
54
 
package/dist/index.cjs CHANGED
@@ -8,6 +8,7 @@ var batchExecute = require('@graphql-tools/batch-execute');
8
8
  var utils = require('@graphql-tools/utils');
9
9
  var promiseHelpers = require('@whatwg-node/promise-helpers');
10
10
  var graphql = require('graphql');
11
+ var delegate = require('@graphql-tools/delegate');
11
12
  var federation = require('@graphql-tools/federation');
12
13
  var merge = require('@graphql-tools/merge');
13
14
  var stitch = require('@graphql-tools/stitch');
@@ -814,6 +815,38 @@ const handleFederationSupergraph = function({
814
815
  }
815
816
  });
816
817
  }
818
+ if (executableUnifiedGraph.getDirective("pubsubPublish")) {
819
+ executableUnifiedGraph = utils.mapSchema(executableUnifiedGraph, {
820
+ [utils.MapperKind.ROOT_FIELD](fieldConfig) {
821
+ const directiveExtensions = utils.getDirectiveExtensions(fieldConfig, executableUnifiedGraph);
822
+ if (directiveExtensions.pubsubPublish?.length) {
823
+ const originalResolve = fieldConfig.resolve || delegate.defaultMergedResolver;
824
+ fieldConfig.resolve = function(root, args, context, info) {
825
+ return promiseHelpers.handleMaybePromise(
826
+ () => originalResolve(root, args, context, info),
827
+ (payload) => {
828
+ const jobs = [];
829
+ for (const pubsubPublishArgs of directiveExtensions.pubsubPublish) {
830
+ const job = context.pubsub?.publish(
831
+ pubsubPublishArgs.pubsubTopic,
832
+ payload
833
+ );
834
+ if (promiseHelpers.isPromise(job)) {
835
+ jobs.push(job);
836
+ }
837
+ }
838
+ if (jobs.length) {
839
+ return Promise.all(jobs).then(() => payload);
840
+ }
841
+ return payload;
842
+ }
843
+ );
844
+ };
845
+ }
846
+ return fieldConfig;
847
+ }
848
+ });
849
+ }
817
850
  return {
818
851
  unifiedGraph: executableUnifiedGraph,
819
852
  inContextSDK,
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ import { defaultPrintFn, createDefaultExecutor } from '@graphql-mesh/transport-c
4
4
  import { resolveAdditionalResolversWithoutImport, getInContextSDK, getResolverForPubSubOperation, isDisposable, iterateAsync, dispose } from '@graphql-mesh/utils';
5
5
  import { getBatchingExecutor } from '@graphql-tools/batch-execute';
6
6
  import { getDirectiveExtensions, mapSchema, MapperKind, astFromField, memoize1, asArray, getDocumentNodeFromSchema, isDocumentNode, printSchemaWithDirectives, mergeDeep, isAsyncIterable, createGraphQLError } from '@graphql-tools/utils';
7
- import { handleMaybePromise, mapAsyncIterator, isPromise } from '@whatwg-node/promise-helpers';
7
+ import { handleMaybePromise, isPromise, mapAsyncIterator } from '@whatwg-node/promise-helpers';
8
8
  import { isInterfaceType, Kind, isObjectType, typeFromAST, isOutputType, GraphQLSchema, GraphQLDirective, parseType, visit, GraphQLString, DirectiveLocation, isEnumType, isSchema, buildSchema, buildASTSchema, print } from 'graphql';
9
+ import { defaultMergedResolver } from '@graphql-tools/delegate';
9
10
  import { getStitchedSchemaFromSupergraphSdl } from '@graphql-tools/federation';
10
11
  import { mergeTypeDefs } from '@graphql-tools/merge';
11
12
  import { createMergedTypeResolver } from '@graphql-tools/stitch';
@@ -812,6 +813,38 @@ const handleFederationSupergraph = function({
812
813
  }
813
814
  });
814
815
  }
816
+ if (executableUnifiedGraph.getDirective("pubsubPublish")) {
817
+ executableUnifiedGraph = mapSchema(executableUnifiedGraph, {
818
+ [MapperKind.ROOT_FIELD](fieldConfig) {
819
+ const directiveExtensions = getDirectiveExtensions(fieldConfig, executableUnifiedGraph);
820
+ if (directiveExtensions.pubsubPublish?.length) {
821
+ const originalResolve = fieldConfig.resolve || defaultMergedResolver;
822
+ fieldConfig.resolve = function(root, args, context, info) {
823
+ return handleMaybePromise(
824
+ () => originalResolve(root, args, context, info),
825
+ (payload) => {
826
+ const jobs = [];
827
+ for (const pubsubPublishArgs of directiveExtensions.pubsubPublish) {
828
+ const job = context.pubsub?.publish(
829
+ pubsubPublishArgs.pubsubTopic,
830
+ payload
831
+ );
832
+ if (isPromise(job)) {
833
+ jobs.push(job);
834
+ }
835
+ }
836
+ if (jobs.length) {
837
+ return Promise.all(jobs).then(() => payload);
838
+ }
839
+ return payload;
840
+ }
841
+ );
842
+ };
843
+ }
844
+ return fieldConfig;
845
+ }
846
+ });
847
+ }
815
848
  return {
816
849
  unifiedGraph: executableUnifiedGraph,
817
850
  inContextSDK,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/fusion-runtime",
3
- "version": "1.1.0",
3
+ "version": "1.2.0-alpha-cb5e4f3ee67b8ef054f1fcf581125aaa3019f6bb",
4
4
  "type": "module",
5
5
  "description": "Runtime for GraphQL Mesh Fusion Supergraph",
6
6
  "repository": {