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

ESM compatibility with plugin code gen #2945

Closed
1 task done
CarsonF opened this issue Jul 28, 2023 · 1 comment
Closed
1 task done

ESM compatibility with plugin code gen #2945

CarsonF opened this issue Jul 28, 2023 · 1 comment
Labels

Comments

@CarsonF
Copy link
Contributor

CarsonF commented Jul 28, 2023

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Currently the plugin emits:

static _GRAPHQL_METADATA_FACTORY() {
  return {
    id: { type: () => String },
    status: { type: () => require("./status").Status },
    items: { type: () => [require("./item").Item] },
  };
}

Describe the solution you'd like

I'd like to change it to this:

static async _GRAPHQL_METADATA_FACTORY() {
  const { Status } = await import("./status");
  const { Item } = await import("./item");
  return {
    id: { type: () => String },
    status: { type: () => Status },
    items: { type: () => [Item] },
  };
}

Maybe not the exact syntax, since I know that matters here with AST work, but that's the idea.
The import/require could be conditional with a new config option. And maybe determined automatically?

Teachability, documentation, adoption, migration strategy

User change is none, other than a config option.

What is the motivation / use case for changing the behavior?

ESM Support

@kamilmysliwiec
Copy link
Member

We already use the await import syntax for metadata files generated for projects that use SWC builder so the migration should be rather seamless.

Anyways, it may take some time before we fully migrate to ESM so let's track this in one place #2568 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants