Skip to content

Conversation

@haikusw
Copy link
Contributor

@haikusw haikusw commented Aug 26, 2020

This addresses #63 "GraphQL parser does not support optional Descriptions"

This adds description support via parseTypeSystemDefinition:

  • SchemaDefinition
  • ScalarTypeDefintion
  • ObjectTypeDefinition
  • InterfaceTypeDefinition
  • UnionTypeDefinition
  • EnumTypeDefinition
  • InputObjectTypeDefinition
  • DirectiveDefinition

others:

  • EnumValueDefinition
  • FieldDefinition
  • InputValueDefinition

This also supports multi-line Descriptions now that the Blockstring PRs #65 and #68 have been merged in, and this includes several tests for those.

All my work has been done on macOS 10.15.6 using Xcode 12b5.

Fixes #63

Doesn’t support multi-line descriptions because string parser currently doesn’t support multi-line strings.

Tests for all additions.

Two strategies used for two different kind of places for descriptions:

1) for items in lists (EnumValueDefinition, FieldDefinition, InputValueDefinition) uses new parseDescription(…) to get the optional description if present.

2) for object definitions where a bunch at the same level have optional descriptions followed by a distinguishing token (SchemaDefinition, ScalarTypeDefintion, ObjectTypeDefinition, InterfaceTypeDefinition, UnionTypeDefinition, EnumTypeDefinition, InputObjectTypeDefinition, DirectiveDefinition) we have to advance the lexer to the distinguishing token so we replace the .string Token in lastToken with a copy with only the token kind set to  new Token kind, .description. Then each of the specific parsers for those Definitions checks .lastToken to see if it’s a kind is .description and if so, uses that for it’s optional description field.

This was the approach that modified the existing code the least and seemed to keep in the spirit of the current implementation.
…are merged in.

prefixed with “fails_” currently so will not be run.
@paulofaria
Copy link
Member

Thank you @haikusw. If you need more inspiration for tests you can check the tests in the canonical implementation:

https://github.com/graphql/graphql-js/tree/master/src/language/__tests__

@haikusw haikusw marked this pull request as ready for review August 27, 2020 22:05
@haikusw
Copy link
Contributor Author

haikusw commented Aug 27, 2020

This is now ready for review and merging if deemed ok. Thanks.

@paulofaria paulofaria merged commit 023af5a into GraphQLSwift:master Aug 27, 2020
@paulofaria
Copy link
Member

Great work @haikusw! Thank you!

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

Successfully merging this pull request may close these issues.

GraphQL parser does not support optional Descriptions.

2 participants