graphql.js icon indicating copy to clipboard operation
graphql.js copied to clipboard

Query merging does not work correctly.

Open urkle opened this issue 4 years ago • 2 comments

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

urkle avatar Dec 11 '21 17:12 urkle

I'm gonna check it.

Fatih Kadir Akın

Edward Rudd @.***> şunları yazdı (11 Ara 2021 ÖS 8:56):

 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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

f avatar Dec 11 '21 18:12 f

@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.

urkle avatar Dec 15 '21 04:12 urkle