Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export easy way for plugins to add PG objects to response #116

Closed
benjie opened this issue Nov 10, 2017 · 1 comment
Closed

Export easy way for plugins to add PG objects to response #116

benjie opened this issue Nov 10, 2017 · 1 comment

Comments

@benjie
Copy link
Member

benjie commented Nov 10, 2017

e.g. a custom mutation might want to expose a DB object on its payload type; this requires importing queryFromResolveData from graphile-build-pg/node8plus/queryFromResolveData currently plus doing a bunch of boilerplate code - we should simplify this.

e.g.

const queryFromResolveData = require("graphile-build-pg/node8plus/queryFromResolveData");
const debugFactory = require("debug");
const debugSql = debugFactory("graphile-build-pg:sql");

// ...

async resolve(parent, args, context, resolveInfo) {
  // ...custom logic here...

  const {
    pgClient,
  } = context;
  const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);
  const resolveData = getDataFromParsedResolveInfoFragment(
    parsedResolveInfoFragment,
    PayloadType
  );
  const query = queryFromResolveData(
    sql.fragment`app_public.teams`,
    undefined,
    resolveData,
    {},
    builder => {
      builder.where(
        sql.fragment`${builder.getTableAlias()}.uuid = ${sql.value(
          team.uuid
        )}`
      );
    }
  );
  const { text, values } = sql.compile(query);
  if (debugSql.enabled) debugSql(text);
  const { rows: [row] } = await pgClient.query(text, values);
  return {
    team: row,
  };
}

could be packaged up for us; it'd be nice to just pass in the table type, the where clause, the context and resolveInfo and have the rest done for us.

@benjie
Copy link
Member Author

benjie commented Aug 16, 2018

This is now all wrapped up with graphile-utils and documented here: https://www.graphile.org/postgraphile/extending/#the-easy-way-graphile-utils

@benjie benjie closed this as completed Aug 16, 2018
madtibo pushed a commit to spacefill/graphile-engine that referenced this issue Dec 7, 2021
madtibo pushed a commit to spacefill/graphile-engine that referenced this issue Dec 7, 2021
madtibo pushed a commit to spacefill/graphile-engine that referenced this issue Dec 7, 2021
madtibo pushed a commit to spacefill/graphile-engine that referenced this issue Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant