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.

Unable to use contextQueries when key contains 2 variables

See original GitHub issue

Maybe I dont get something but this code produces this error: Type '[string, string]' is not assignable to type 'readonly [ValidValue]'. Source has 2 element(s) but target allows only 1.

export const keys = createQueryKeys('user', {
  byId: (accountId: string, userId: string) => ({
    queryKey: [accountId, userId],
    contextQueries: {
      likes: null,
    },
  }),
});

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lukemoralescommented, Nov 22, 2022

@Kamahl19 oh yeah, definitely outdated examples, thanks for bringing me attention to them. I’ll make sure to update the readme and prevent this confusion again.

0reactions
Kamahl19commented, Nov 22, 2022

@lukemorales Sorry for my naive question but… why not a simple API supporting all valid keys such as:

const queryKeys = createQueryKeys({
  user: () => ({
    key: ['user'],
    children: {
      list: (filters) => ({
        key: ['list', filters],
      }),
      byId: (userId) => ({
        key: ['byId', userId],
        children: {
          likes: () => ({
            key: ['likes'],
          }),
        },
      }),
    },
  }),
});

There is no magic (prepending strings based on obj keys), no null keys, it allows all valid query keys and no _ctx and _def fields.

The output would be:

{
  user: {
    queryKey: ['user'],
    list: (filters) => ({
      queryKey: ['user', 'list', filters],
    }),
    byId: (userId) => ({
      key: ['user', 'byId', userId],
      likes: () => ({
        key: ['user', 'byId', userId, 'likes'],
      }),
    }),
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework - "Unable to create a constant value of type ...
The problem is, that EF a complex type, that is passed in the "Contains"-parameter, can not translate into an SQL query. EF can...
Read more >
Using contexts and variables - Cloud - 8.0 - Talend Help Center
Variables represent values which change throughout the execution of a program. A global variable is a system variable which can be accessed by...
Read more >
API Connect context variables - IBM
Name Description Permission api.catalog.path The path segment that represents this Catalog. Read/write api.endpoint.address The address of the API Gateway endpoint. Read/write api.id The identifier of the...
Read more >
Chapter 4. Query Performance Optimization - O'Reilly
In the previous chapter, we explained how to optimize a schema, which is one of the necessary conditions for high performance.
Read more >
Relationships, navigation properties, and foreign keys - EF6
The model contains two entities that participate in one-to-many relationship. Both entities have navigation properties. Course is the dependent ...
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