cube-js/cube

Support multiple CubeProviders

Open

#4889 opened on Jul 11, 2022

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Rust (19,563 stars) (1,965 forks)batch import
help wanted

Description

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

I have a React application that needs to query two different cube services. However, the <CubeProvider> component only supports specifying a single Cube service, and if <CubeProvider>s are nested, then only the innermost client object will be available.

Describe the solution you'd like

Add an optional name prop to <CubeProvider>, with a default value of “default”. The internal CubeContext, rather than holding a single client object, would hold an object mapping names to clients.

Hooks that presently accept an optional client argument would also accept a string value for that argument. If a string is provided, the hook would use the client with that name from the context, if it exists, or throw an error otherwise. If no value is passed, it would use the “default” client (matching current behavior).

Describe alternatives you've considered

As a workaround, I've written my own <CubeProvider> implementation that allows multiple clients. To use this with the existing hooks requires manually extracting the client instance from the context. A built-in implementation would be better.

As an alternative to the existing hooks accepting strings, we could directly expose a hook that gets a client by name, then expect the user to call this hook and pass the client object to the existing hook. This would arguably be a smaller change.

As an alternative to using the string “default” as a default name, we could treat an un-named client specially. This would arguably be cleaner in a way, but it would also be more complicated, and I don't see the need.

I am willing to work on this.

Contributor guide