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

Feature Request: replication-graphql, Allow specifying the data path #2606

Closed
angelnar87 opened this issue Oct 15, 2020 · 3 comments
Closed

Comments

@angelnar87
Copy link

The current code assumes that the data for graphql replication is always the first child of the response. It would be nice if this was actually configurable so that us as developers could specify a different root; in case that the actual data is 2 levels (or 3 or whatever) deep in the response.

Not an issue; just a would-be-nice-to-have 🙂

@christofu
Copy link

christofu commented Oct 16, 2020

Agreed. We're using postgraphile which kind of wants to return the nodes under the 'nodes' property on the response). To get around it for now we updated src/plugins/replication-graphql/index.ts to match our specific use case in runPull, adding in

// this assumes that there will be always only one property in the response
// is this correct? it is not. Some graphql servers (at least postgraphile) will return a list of
// nodes as an array under the 'nodes' property which therefore needs to be flattened.
// This probably should check if there is any property that is an array and use that, instead
// of just checking for 'nodes'
const initialData = result.data[Object.keys(result.data)[0]];
const data = initialData.nodes !== undefined && Array.isArray(initialData.nodes) ? initialData.nodes: initialData;

but I agree that this would be nice as a configuration option!

@pubkey
Copy link
Owner

pubkey commented Oct 16, 2020

Yes you are right.
We should make this an optional setting and use the first field if not set.

PR is welcomed.

Another solution would be to give the whole data property into the pull modifier and the modifier should then return an array instead of a single object. I think this would be less magic but also a breaking change.

@pubkey
Copy link
Owner

pubkey commented Nov 16, 2020

I am closing this since there is no progress.
PR is still welcomed.

@pubkey pubkey closed this as completed Nov 16, 2020
joshmcarthur added a commit to joshmcarthur/rxdb that referenced this issue May 28, 2021
…ion pull object to specify where to fetch result documents from
joshmcarthur added a commit to joshmcarthur/rxdb that referenced this issue May 28, 2021
…ion pull object to specify where to fetch result documents from
pubkey added a commit that referenced this issue Jun 30, 2021
#2606: Allow 'dataPath' to be specified on the GraphQL replication pull object to specify where to fetch result documents from
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

No branches or pull requests

3 participants