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

Query merging does not work correctly. #61

Open
urkle opened this issue Dec 11, 2021 · 2 comments
Open

Query merging does not work correctly. #61

urkle opened this issue Dec 11, 2021 · 2 comments

Comments

@urkle
Copy link
Contributor

urkle commented Dec 11, 2021

I have the following setup

export const graph = graphql('/graphql', {
  method: 'POST',
  asJSON: true,
  debug: true,
});

graph.fragment({
  video: `on Video {
    id
    description
    duration
    videoType
  }`,
  category: `on Category {
    id
    name
    categoryType
  }`,
});

export const videos = graph.query('{ videos { ...video } }');

export const categories = graph.query('{ categories { ...category } }');

I try to use the "merge" functionality like so.

queries.videos.merge('test');
queries.categories.merge('test');
queries.graph.commit('test').then((r) => console.log('all', r));

Now the query sent to my server is as follows.

query  {
merge993382_videos :{ videos { ... video } }
merge278951_categories :{ categories { ... category } }
 }

fragment video on Video {
    id
    description
    duration
    videoType
  }

fragment category on Category {
    id
    name
    categoryType
  }

Which is, of course, invalid as the extra {} shouldn't be there around the query pieces.

I'm using graphql.js version 0.6.7

@f
Copy link
Owner

f commented Dec 11, 2021 via email

@urkle
Copy link
Contributor Author

urkle commented Dec 15, 2021

@f I added a PR (#62) which fixes this bug. It also adds a jest-based test rig to make it easier to do automated tests.

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

2 participants