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

(graphcache) - Change Store constructor to accept options object #622

Merged
merged 4 commits into from
Mar 16, 2020

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 16, 2020

This changes cacheExchange to just pass on its options and Store to accept an options object as well to make it easier to use directly.

// before:
new Store(
  undefined, // schema
  { /* resolvers */ },
  { /* updates */ },
  { /* optimistic */ },
  { /* keys */ },
);

// after:
new Store({
  schema: undefined,
  resolvers: {},
  updates: {},
  optimistic: {},
  keys: {},
});

storage is exempted since the rehydration logic is coupled to the cacheExchange (for now). Bundle size remains unchanged.

@kitten kitten requested a review from JoviDeCroock March 16, 2020 10:52
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2020

🦋 Changeset is good to go

Latest commit: 17d88df

We got this.

This PR includes changesets to release 1 package
Name Type
@urql/exchange-graphcache 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

Copy link
Collaborator

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

That's a good shout 👍

@@ -86,12 +86,10 @@ export const cacheExchange = (opts?: CacheExchangeOpts): Exchange => ({
forward,
client,
}) => {
if (!opts) opts = {};
Copy link
Contributor

@andyrichardson andyrichardson Mar 16, 2020

Choose a reason for hiding this comment

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

Good shout on removing this!

Default params also save us some conditional logic:

opts?: CacheExchangeOpts = {}

Copy link
Member Author

Choose a reason for hiding this comment

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

To be fair, I've just moved it 😆 but typically transpilers will jump through more hoops in the generated code with default params rather than reassigning the argument. It's a minor details though, since we do get the type safety from TypeScript in either cases 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

default params are very expensive size wise, see this REPL

@kitten kitten force-pushed the fix/store-constructor-interface branch from 4e0f021 to 17d88df Compare March 16, 2020 11:08
@kitten kitten changed the title Change Store constructor to accept options object (graphcache) - Change Store constructor to accept options object Mar 16, 2020
@kitten kitten merged commit 3a99b2e into master Mar 16, 2020
@kitten kitten deleted the fix/store-constructor-interface branch March 16, 2020 11:16
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

Successfully merging this pull request may close these issues.

3 participants