question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad TS types prevent setting of defaultOptions

See original GitHub issue

I get a type error with this code:

const client = new AWSAppSyncClient(
  {
    url: appSyncConfig.graphqlEndpoint,
    region: appSyncConfig.region,
    auth: {
      type: appSyncConfig.authenticationType,
      // credentials: () => Auth.currentCredentials(),
      apiKey: () => appSyncConfig.apiKey,
    },
  },
  {
    defaultOptions: {
      watchQuery: {
        fetchPolicy: 'cache-and-network',
      },
    },
  }
);
ERROR in /Volumes/SuperData/Sites/reelcrafter/rc-ts/src/bootstrap/apollo-setup.ts
17:3 Argument of type '{ defaultOptions: { watchQuery: { fetchPolicy: "cache-and-network"; }; }; }' is not assignable to parameter of type 'ApolloClientOptions<InMemoryCache>'.
  Property 'link' is missing in type '{ defaultOptions: { watchQuery: { fetchPolicy: "cache-and-network"; }; }; }'.
    15 |     },
    16 |   },
  > 17 |   {
       |   ^
    18 |     defaultOptions: {
    19 |       watchQuery: {
    20 |         fetchPolicy: 'cache-and-network',

ApolloClientOptions requires link and cache to be passed. We need a way to be able to set the global fetchPolicy.

This code functions properly, and sets the right fetch policy. It’s just that the type used is probably not the best option. I’m looking into somehow creating a new interface based off of ApolloClientOptions that doesn’t have link and cache in it.

@manueliglesias I’m open to other ideas as well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ffxsamcommented, Aug 15, 2018

@manueliglesias Works great!

0reactions
manueliglesiascommented, Aug 14, 2018

Cool! It would be great if you can try the code from #226

Read more comments on GitHub >

github_iconTop Results From Across the Web

[ban-types] Default options are never removed · Issue #686
I'm OK with the default rule, e.g., for Object, but I don't like that there's no way to disable (or change) the fixWith...
Read more >
ban-ts-comment - TypeScript ESLint
TypeScript provides several directive comments that can be used to alter how it processes files. Using these to suppress TypeScript compiler errors reduces ......
Read more >
Setting default value for TypeScript object passed as ...
The trick is to first put in brackets what keys you want to pick from the argument object, with key=value for any defaults....
Read more >
Configuring Vitest
To configure vitest itself, add test property in your Vite config ... You can retrieve Vitest's default options to expand them if needed:...
Read more >
Documentation - Do's and Don'ts
WRONG */. function reverse(s: String): String;. ✓ Do use the types number , string ... Don't ever have a generic type which doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found