UNPKG

apollo-schema-extend

Version:

Extends your Apollo Server Express based graphql server with an external graphql source

24 lines (23 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addSelections = exports.withSelections = exports.createField = void 0; const graphql_1 = require("graphql"); const createName = (name) => (name ? { kind: graphql_1.Kind.NAME, value: name } : undefined); /** * Creates a field AST * @param {string} name * @param {string|undefined} alias */ const createField = (name, alias) => ({ alias: createName(alias), arguments: [], directives: [], kind: graphql_1.Kind.FIELD, name: createName(name), selectionSet: undefined, }); exports.createField = createField; const withSelections = (node, selections) => (Object.assign(Object.assign({}, node), { selectionSet: Object.assign(Object.assign({}, node.selectionSet), { kind: 'SelectionSet', selections }) })); exports.withSelections = withSelections; const addSelections = (node, ...selections) => { var _a, _b; return (0, exports.withSelections)(node, [...((_b = (_a = node.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) !== null && _b !== void 0 ? _b : []), ...selections]); }; exports.addSelections = addSelections;