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

Documentation - modify introspection results #125

Open
1 of 3 tasks
dan-barbulescu opened this issue Apr 1, 2019 · 2 comments
Open
1 of 3 tasks

Documentation - modify introspection results #125

dan-barbulescu opened this issue Apr 1, 2019 · 2 comments

Comments

@dan-barbulescu
Copy link

I'm submitting a ...

  • bug report
  • feature request
  • question

PostGraphile version: 4.3.3

You mentioned the possibility of changing introspection results to switch data types. Please provide some examples on how to do this.

Additionally, it would be nice to know how to add things to the introspection results (i.e. to implement additional smart comments).

@benjie
Copy link
Member

benjie commented Apr 12, 2019

Introspection results are available via the pgIntrospectionResultsByKind object on Build; but for your changes to take effect you must make any changes before other plugins use the introspection results. One way to achieve this is using the new dependencies system; e.g.:

module.exports = builder => {
  builder.hook(
    // Hook name:
    'build',
    // Hook function:
    build => {
      const attribute = build.pgIntrosectionResultsByKind.attribute.find(
        attr => attr.name === 'my_column' && attr.class && attr.class.name === 'my_table' && attr.class.namespaceName === 'my_schema'
      );
      if (attr) {
        const newTypeId = '23'; // OID 23 is an int4
        attr.typeId = newTypeId;
        attr.type = build.pgIntrospectionResultsByKind.type.find(t => t.id === newTypeId);
      }
      // Must return input, or a derivative thereof
      return build;
    },
    // Provides: We don't particularly provide anything, so empty:
    [],
    // Before: Must be before PgTypes (where the type is first used):
    ['PgTypes'],
    // After: Must be after PgIntrospection (otherwise pgIntrospectionResultsByKind doesn't exist):
    ['PgIntrospection']
  );
};

Adding tags/etc is done in the same way, in this case it'd be attr.tags.myNewTag = 'foo'; you can see an example of this here: https://www.graphile.org/postgraphile/plugin-gallery/#Customisation__OmitMutationsByDefaultPlugin

You can see a list of the types and their fields here:

https://github.com/graphile/graphile-engine/blob/master/packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.d.ts

@benjie
Copy link
Member

benjie commented Apr 12, 2019

Moving to website repo

@benjie benjie transferred this issue from graphile/crystal Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@benjie @dan-barbulescu and others