Skip to content

Conversation

@benjie
Copy link
Member

@benjie benjie commented May 21, 2020

Some massive improvements to mergeAsts:

  • Doesn't inline fields/fragments if they use directives
  • Doesn't drop following selection sets using same field name (merges them instead)
  • Factors in types if optional schema is provided, allowing for deeper merging (i.e. no more ... on User {...} when you're already referring to the User type)
  • Stronger types throughout
  • Tighter conversion to InlineFragment (doesn't add extraneous attributes)
  • Still manages this on a single visit
@acao acao added this to the GraphiQL-1.0.0 milestone May 21, 2020
@acao acao changed the base branch from master to main June 19, 2020 14:37
@benjie benjie force-pushed the merge-ast-type-aware branch from db2dd61 to 20383bc Compare June 24, 2020 13:56
@acao
Copy link
Member

acao commented Jun 24, 2020

hey @benjie ! do you want to change this to target 1.0.0 for now, and then we can port it over to the 2.0.0 rewrite when it's released for 1.0.0 users?

@benjie benjie force-pushed the merge-ast-type-aware branch from ea1f85a to c160a30 Compare June 25, 2020 13:27
@benjie benjie marked this pull request as ready for review June 25, 2020 13:36
@acao
Copy link
Member

acao commented Jun 25, 2020

looking great @benjie!
unfortunately there isn't a way to manually test this yet since the merge capability was amongst what was temporarily disabled
https://deploy-preview-1542--graphiql-test.netlify.app/bundle/dist/

do we need more test cases for this, possibly? potentially some to make sure we see directives left alone, etc?

@acao
Copy link
Member

acao commented Jun 25, 2020

maybe also a test to confirm that it preserves comments? that's been a highly requested feature

@benjie
Copy link
Member Author

benjie commented Jun 25, 2020

unfortunately there isn't a way to test this yet since the merge capability was amongst what was temporarily disabled

That's okay; we still pass the unit tests (which I've re-enabled and expanded), so we can be pretty confident that it'll still work at least as well as the old version did:

From CI: PASS graphiql packages/graphiql/src/utility/__tests__/mergeAst.spec.ts

maybe also a test to confirm that it preserves comments? that's been a highly requested feature

It does not preserve comments; neither does the old version. Yes this would be nice; but it's an entirely different body of work out of scope of this PR (AFAIK the AST doesn't include comments, so we'd need to grab these from the source and then some how re-apply them at the end like prettier does; this is quite an undertaking). Also it poses its own challenges about how comments should be merged.

@acao
Copy link
Member

acao commented Jun 25, 2020

ah! this explains a lot. i wonder if it's planned for comments to be available in AST?

@acao
Copy link
Member

acao commented Jun 25, 2020

@benjie let's call this good to merge, looks great to me locally, and then I can backport it to 1.0.x for a nice treat :D

@benjie
Copy link
Member Author

benjie commented Jun 25, 2020

Awesome; merge at will. Most ASTs don’t contain comments (they’re generally skipped by the lexer as if they were whitespace) but it’d certainly be a welcome addition.

@acao acao merged commit a62a4ec into main Jun 25, 2020
@acao acao deleted the merge-ast-type-aware branch June 25, 2020 19:35
harshithpabbati pushed a commit to harshithpabbati/graphiql that referenced this pull request Jul 3, 2020
Signed-off-by: harshithpabbati <pabbatiharshith@gmail.com>
thenamankumar pushed a commit to thenamankumar/graphiql that referenced this pull request Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants