@omnigraph/mongo 0.0.0-stage → 0.1.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.
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapMongoPathToGraphQL = mapMongoPathToGraphQL;
4
+ exports.mapMongoPathToList = mapMongoPathToList;
5
+ const graphql_1 = require("graphql");
6
+ const graphql_scalars_1 = require("graphql-scalars");
7
+ /**
8
+ * Map a Mongoose / BSON path instance type name to a GraphQL output type.
9
+ * Sole document PK (`_id` / asId) uses GraphQL `ID` (federation-friendly).
10
+ * Other ObjectId paths keep graphql-scalars `ObjectID`.
11
+ */
12
+ function mapMongoPathToGraphQL(instance, opts) {
13
+ if (opts?.asId) {
14
+ return graphql_1.GraphQLID;
15
+ }
16
+ if (instance === 'ObjectID' || instance === 'ObjectId') {
17
+ return graphql_scalars_1.GraphQLObjectID;
18
+ }
19
+ switch (instance) {
20
+ case 'String':
21
+ return graphql_1.GraphQLString;
22
+ case 'Number':
23
+ return graphql_1.GraphQLFloat;
24
+ case 'Decimal128':
25
+ return graphql_1.GraphQLString;
26
+ case 'Boolean':
27
+ return graphql_1.GraphQLBoolean;
28
+ case 'Date':
29
+ return graphql_scalars_1.GraphQLDateTime;
30
+ case 'Buffer':
31
+ return graphql_scalars_1.GraphQLByte;
32
+ case 'Mixed':
33
+ case 'Array':
34
+ return graphql_scalars_1.GraphQLJSON;
35
+ case 'Map':
36
+ return graphql_scalars_1.GraphQLJSON;
37
+ case 'Int32':
38
+ return graphql_1.GraphQLInt;
39
+ case 'Double':
40
+ return graphql_1.GraphQLFloat;
41
+ default:
42
+ return graphql_scalars_1.GraphQLJSON;
43
+ }
44
+ }
45
+ function mapMongoPathToList(inner) {
46
+ return new graphql_1.GraphQLList(inner);
47
+ }
@@ -0,0 +1,58 @@
1
+ import { DirectiveLocation, GraphQLDirective, GraphQLEnumType, GraphQLNonNull, GraphQLString, } from 'graphql';
2
+ /**
3
+ * Single kind enum for `@mongo` (reads, writes, aggregates).
4
+ */
5
+ export const MongoKindEnum = new GraphQLEnumType({
6
+ name: 'MongoKind',
7
+ values: {
8
+ FIND_ONE: { value: 'FIND_ONE' },
9
+ FIND_MANY: { value: 'FIND_MANY' },
10
+ COUNT: { value: 'COUNT' },
11
+ CONNECTION: { value: 'CONNECTION' },
12
+ PAGINATION: { value: 'PAGINATION' },
13
+ AGGREGATE: { value: 'AGGREGATE' },
14
+ INSERT_ONE: { value: 'INSERT_ONE' },
15
+ INSERT_MANY: { value: 'INSERT_MANY' },
16
+ UPDATE_ONE: { value: 'UPDATE_ONE' },
17
+ UPDATE_MANY: { value: 'UPDATE_MANY' },
18
+ DELETE_ONE: { value: 'DELETE_ONE' },
19
+ DELETE_MANY: { value: 'DELETE_MANY' },
20
+ },
21
+ });
22
+ export const MongoDirective = new GraphQLDirective({
23
+ name: 'mongo',
24
+ // FIELD: Query/Mutation/nested. OBJECT: type-level entity resolver (`$this` keys).
25
+ locations: [DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT],
26
+ args: {
27
+ subgraph: { type: GraphQLString },
28
+ collection: { type: new GraphQLNonNull(GraphQLString) },
29
+ kind: { type: new GraphQLNonNull(MongoKindEnum) },
30
+ /**
31
+ * Equality / join predicates plus Connectors-style spreads
32
+ * (`_id: $this.id`, `...$args.filter`). Mongo-native `filter` naming.
33
+ */
34
+ filter: { type: GraphQLString },
35
+ /** @deprecated use `filter` */
36
+ where: { type: GraphQLString },
37
+ /** Sort binder (`$args.sort`). */
38
+ sort: { type: GraphQLString },
39
+ /** Limit binder (`$args.limit`). */
40
+ limit: { type: GraphQLString },
41
+ /** Skip binder (`$args.skip`). */
42
+ skip: { type: GraphQLString },
43
+ /** CONNECTION page size (`$args.first`). */
44
+ first: { type: GraphQLString },
45
+ /** CONNECTION cursor (`$args.after`). */
46
+ after: { type: GraphQLString },
47
+ /** PAGINATION page (`$args.page`). */
48
+ page: { type: GraphQLString },
49
+ /** PAGINATION page size (`$args.perPage`). */
50
+ perPage: { type: GraphQLString },
51
+ /** Document values for INSERT / UPDATE. */
52
+ set: { type: GraphQLString },
53
+ selection: { type: GraphQLString },
54
+ /** Aggregate pipeline stages (JSON array string or mapping). */
55
+ pipeline: { type: GraphQLString },
56
+ },
57
+ });
58
+ export { TransportDirective } from '@graphql-mesh/utils';
@@ -0,0 +1,16 @@
1
+ import { process as meshProcess } from '@graphql-mesh/cross-helpers';
2
+ import { loadGraphQLSchemaFromMongo } from './schema.js';
3
+ export * from './directives.js';
4
+ export * from './naming.js';
5
+ export * from './schema.js';
6
+ export * from './type-map.js';
7
+ export function loadMongoSubgraph(name, opts) {
8
+ return () => ({
9
+ name,
10
+ schema$: loadGraphQLSchemaFromMongo(name, {
11
+ ...opts,
12
+ cwd: opts.cwd || meshProcess.cwd(),
13
+ }),
14
+ });
15
+ }
16
+ export { getMongoExecutor } from '@graphql-mesh/transport-mongo';
@@ -0,0 +1,30 @@
1
+ export function createDefaultNaming() {
2
+ return {
3
+ typeName: name => name,
4
+ filterInput: typeName => `${typeName}Filter`,
5
+ sortInput: typeName => `${typeName}Sort`,
6
+ createInput: typeName => `CreateOne${typeName}Input`,
7
+ updateInput: typeName => `UpdateById${typeName}Input`,
8
+ payloadType: typeName => `${typeName}Payload`,
9
+ connectionType: typeName => `${typeName}Connection`,
10
+ edgeType: typeName => `${typeName}Edge`,
11
+ paginationType: typeName => `${typeName}Pagination`,
12
+ findByIdField: typeName => `${typeName}_findById`,
13
+ findByIdsField: typeName => `${typeName}_findByIds`,
14
+ findManyField: typeName => `${typeName}_findMany`,
15
+ findOneField: typeName => `${typeName}_findOne`,
16
+ countField: typeName => `${typeName}_count`,
17
+ connectionField: typeName => `${typeName}_connection`,
18
+ paginationField: typeName => `${typeName}_pagination`,
19
+ dataLoaderField: typeName => `${typeName}_dataLoader`,
20
+ dataLoaderManyField: typeName => `${typeName}_dataLoaderMany`,
21
+ createOneField: typeName => `${typeName}_createOne`,
22
+ createManyField: typeName => `${typeName}_createMany`,
23
+ updateByIdField: typeName => `${typeName}_updateById`,
24
+ updateOneField: typeName => `${typeName}_updateOne`,
25
+ updateManyField: typeName => `${typeName}_updateMany`,
26
+ removeByIdField: typeName => `${typeName}_removeById`,
27
+ removeOneField: typeName => `${typeName}_removeOne`,
28
+ removeManyField: typeName => `${typeName}_removeMany`,
29
+ };
30
+ }