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

Remove default filter from WellKnownMap #2180

Merged
merged 4 commits into from
Sep 23, 2024
Merged

Conversation

nckswt
Copy link
Contributor

@nckswt nckswt commented Sep 20, 2024

Description

I noticed an issue where some modules weren't being exported properly. Full discord discussion here.

Problem

My source code has:

import CityTimezones from 'city-timezones';
import snakeCase from 'lodash/snakeCase';

...
export const pgInsert = EXPORTABLE((snakeCase) => async (pgClient, table, data) => {
  const columns = Object.keys(data).map(snakeCase).join(', ');
  ...
}, [snakeCase]);

and I'm exporting modules like:

import * as CityTimezones from 'city-timezones';
import * as lodashSnakeCase from 'lodash/snakeCase';

...
  await exportSchema(schema, exportFileLocation, {
    mode: "typeDefs",
    modules: {
      'city-timezones': CityTimezones,
      'lodash/snakeCase': lodashSnakeCase,
    }
  });

But my exported schema has snakeCase undefined:

const pgInsert2 = async (pgClient, table, data) => {
  const columns = Object.keys(data).map(undefined).join(", ");
  // !! Note how snakeCase has become undefined /\

Resolution

After this line I added the following:

  console.log({ moduleName, exportName, exp: obj[exportName] });
  console.log(exportName !== "default");
  console.log(!wellKnownMap.has(obj[exportName]));

and noticed

{
  moduleName: 'city-timezones',
  exportName: 'lookupViaCity',
  exp: [Function: lookupViaCity]
}
true
true
{
  moduleName: 'lodash/snakeCase',
  exportName: 'default',
  exp: [Function (anonymous)]
}
false
true

So, for now, I'm simply removing the exportName !== "default" conditional and my schema seems to be exported as expected, but I don't know why that was there in the first place or the other downstream effects.

Performance impact

unknown, likely none.

Security impact

unknown, likely none.

Checklist

  • My code matches the project's code style and yarn lint:fix passes.
  • I've added tests for the new feature, and yarn test passes.
  • I have detailed the new feature in the relevant documentation.
  • I have added this feature to 'Pending' in the RELEASE_NOTES.md file (if one exists).
  • If this is a breaking change I've explained why.

Copy link

changeset-bot bot commented Sep 20, 2024

🦋 Changeset detected

Latest commit: 4cc6d36

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
graphile-export Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…ault export (`import mod from 'mod'`) differed from wildcard export (`import * as mod from 'mod'`).
benjie
benjie previously approved these changes Sep 23, 2024
Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Hopefully this is a more thorough fix and cleans up some existing code too 👍

@benjie benjie merged commit fbb1b31 into graphile:main Sep 23, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants