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

Ability to extend the template API #1

Open
richardguerre opened this issue Jul 26, 2021 · 0 comments
Open

Ability to extend the template API #1

richardguerre opened this issue Jul 26, 2021 · 0 comments

Comments

@richardguerre
Copy link
Owner

The idea is to allow for even more customization by being able to extend the template API.

The current template API is:

export type TemplateProps = {
  componentName: string;
  fragments: TemplateFragment[];
  query: TemplateQuery;
};

export type TemplateFragment = {
  name: string;
  propName: string;
  raw: string;
  selectionSet: string[];
};

export type TemplateQuery = {
  raw: string;
  fragments: {
    propName: string;
    dataPath: string;
  }[];
};

But it would be nice to have isPaginationFragment in the TemplateFragment type so that you can conditionally render a usePaginationFragment instead of useFragment.

To extend, there could be a extension.(js|ts) file inside .relay-butler that exports a function that takes in config (the config object defined in .relay-butler/config.js), api (the default output of relay-butler's template API), and ast (the parsed AST object from running graphql.parse(input) on the contents of input.graphql) and outputs a new API.
For example:

// extension.js
module.exports = (config, api, ast) => {
  if(ast.definitions.find((def) => def.type === 'MyType')) {
    api.isMyType = true;
  }

  return api;
}

Add 👍 to upvote.

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

1 participant