How to use graphile-utils - 10 common examples

To help you get started, we’ve selected a few graphile-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enisdenjo / relay-modern-boilerplate / postgraphile / plugins / PgIdToRowIdInflectorPlugin.js View on Github external
*  `articleId` -> `articleRowId`
 *  `user_row_id` -> `user_row_id` (will stay the same if `id` is prefixed with `row_`)
 *  `userRowId` -> `userRowId` (will stay the same if `Id` is prefixed with `Row`)
 */

const { makeAddInflectorsPlugin } = require('graphile-utils');

function replaceIdWithRowId(str) {
  return str
    .replace(/(?
github alex-ald / postgraphile-nest / lib / factories / plugin.factory.ts View on Github external
throw new Error('typeName, fieldName, and fieldType are required for ExtendSchema');
    }

    typeName = typeName.trim();
    fieldName = fieldName.trim();

    const matches = fieldName.match(/^\w+/);

    // If no field name exists, then ignore creating the plugin
    if (isNil(matches)) {
      throw new Error('Unable to create ExtendSchema plugin because a field name'
        + ' was not provided or is not in correct form. fieldname: ' + fieldName);
    }

    const fieldNameWithoutParams = matches[0];
    return makeExtendSchemaPlugin(build => {
      return {
        typeDefs: gql`
          ${additionalGraphql}

          extend type ${typeName} {
            ${fieldName}: ${fieldType}
          }
        `,
        resolvers: {
          [typeName]: {
            [fieldNameWithoutParams]: async (query, args, context, resolveInfo) => {
              return await resolver(query, args, context, resolveInfo, build);
            },
          },
        },
      };
github alex-ald / postgraphile-nest / lib / factories / plugin.factory.ts View on Github external
public static createWrapResolverPlugin(
    typeName: string,
    fieldName: string,
    requirements: ResolverWrapperRequirements,
    // tslint:disable-next-line:ban-types
    resolver: Function,
  ) {
    if (!typeName || !fieldName) {
      throw new Error('typeName and fieldName are required for WrapResolver');
    }

    typeName = typeName.trim();
    fieldName = fieldName.trim();

    return makeWrapResolversPlugin({
      [typeName]: {
        [fieldName]: {
          requires: requirements,
          // tslint:disable-next-line:ban-types
          resolve: resolver as any,
        },
      },
    });
  }
github clevertech / boilerplate / api / plugins / LoginJwtHook / index.js View on Github external
if (!jwt) {
        throw new Error("Authentication failed")
      }
      try {
        const signedJwt = signJwt(jwt)
        await redisJwtHelper.whitelistJwt(signedJwt)
        context.responseHelper.setJwtCookie(signedJwt)
      } catch (e) {
        console.error(e)
      }
      return null
    },
  }
}

export default makeWrapResolversPlugin(wrapResolversPlugin);
github graphile / postgraphile / src / plugins.ts View on Github external
const plugin: Plugin = (builder, options) => {
    function handleTagsError(err: Error): void {
      console.error(`Failed to process smart tags file '${tagsFile}': ${err.message}`);
    }

    const initialTagsJSON: JSONPgSmartTags = JSON5.parse(readFileSync(tagsFile, 'utf8'));

    let tagsListener: null | ((current: Stats, previous: Stats) => void) = null;
    const smartTagsPlugin = makeJSONPgSmartTagsPlugin(initialTagsJSON, updateJSON => {
      if (tagsListener) {
        unwatchFile(tagsFile, tagsListener);
        tagsListener = null;
      }
      if (updateJSON) {
        tagsListener = (_current, _previous): void => {
          readFile(tagsFile, 'utf8', (err, data) => {
            if (err) {
              if (err['code'] === 'ENOENT') {
                updateJSON(null);
              } else {
                handleTagsError(err);
              }
              return;
            }
            try {
github alex-ald / postgraphile-nest / lib / factories / plugin.factory.ts View on Github external
public static createAddInflectorsPlugin(
    inflectorName: string,
    method: (...args: any[]) => any,
    overwriteExisting?: boolean,
  ) {
    return makeAddInflectorsPlugin(
      { [inflectorName]: method },
      overwriteExisting,
    );
  }
}
github graphile / bootstrap-react-apollo / server / plugins / authentication.js View on Github external
const { makeExtendSchemaPlugin, gql } = require("graphile-utils");

const PassportLoginPlugin = makeExtendSchemaPlugin(build => ({
  typeDefs: gql`
    input RegisterInput {
      username: String!
      email: String!
      password: String!
      name: String
      avatarUrl: String
    }

    type RegisterPayload {
      user: User! @pgField
    }

    input LoginInput {
      username: String!
      password: String!
github alex-ald / postgraphile-nest / lib / services / schema-type-explorer.service.ts View on Github external
public getCombinedPlugin() {
    const modules = this.getModules();

    const plugins: Plugin[] = this.evaluateModules(modules, instance =>
      this.filterAttachPlugins(instance),
    );

    return makePluginByCombiningPlugins(...plugins);
  }
github alex-ald / postgraphile-nest / lib / services / plugin-explorer.service.ts View on Github external
public getCombinedPlugin() {
    const modules = this.getModules();

    const plugins: Plugin[] = this.evaluateModules(modules, instance =>
      this.filterAttachPlugins(instance),
    );

    return makePluginByCombiningPlugins(...plugins);
  }
github alex-ald / postgraphile-nest / lib / factories / plugin.factory.ts View on Github external
public static createChangeNullabilityPlugin(
    typeName: string,
    fieldName: string,
    isNullable: boolean,
  ) {
    if (!typeName || !fieldName) {
      throw new Error('typeName and fieldName are required for ChangeNullability');
    }

    typeName = typeName.trim();
    fieldName = fieldName.trim();

    return makeChangeNullabilityPlugin({
      [typeName]: {
        [fieldName]: isNullable,
      },
    });
  }