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

relay-compiler 13 custom transforms #3899

Open
mle-moni opened this issue May 5, 2022 · 2 comments
Open

relay-compiler 13 custom transforms #3899

mle-moni opened this issue May 5, 2022 · 2 comments

Comments

@mle-moni
Copy link

mle-moni commented May 5, 2022

It would be nice to be able to add custom transforms like it was possible in v12

in our project we used it to add some code in generated files

// our code is something like
import { relayCompiler } from 'relay-compiler';

const tsPluginDefault = require('relay-compiler-language-typescript').default();
const { inputExtensions, outputExtension, findGraphQLTags, typeGenerator } = tsPluginDefault;

const langPlugin = {
    inputExtensions,
    outputExtension,
    findGraphQLTags,
    // in the formatModule we transform the ouput files to add some code specific to the request
    formatModule: ourSpecificFormatModule,
    typeGenerator,
}

await relayCompiler({
    ...moreConfig,
    language: langPlugin,
});
@voideanvalue
Copy link
Contributor

I agree that it would be nice. The new compiler is implemented in Rust. Some searching led me to https://nullderef.com/blog/plugin-tech/. I'm not sure what the best approach for creating a plugin system for the new compiler might be. Optimizing compiler perf for large scale projects was one of the reasons for the Rust rewrite. We'd also need to think about performance implications and the sort of constrains we'd want for the plugin system.

As far as I'm aware, the relay team has no plans to investigate this space.

What sort of additional information are you looking to add? Maybe there's a simpler way to enable that without a proper plugin system for custom transforms.

@mle-moni
Copy link
Author

mle-moni commented May 6, 2022

We use graphql on the backend and we generate queries with relay-compiler, but for some queries we add some functions, mainly CRUD utils:
e.g. in this query :

query getMissionQuery(
  $id: MissionId!
) @generateCRUD {
  EU {
    findOne {
      Mission(id: $id) {
        SOME_FIELD
        SOME_OTHER_FIELD
      }
    }
  }
}

we would generate the functions: createMission, readMission, updateMission and deleteMission

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

2 participants