-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add support for Apollo Connectors Mapping Syntax #230
Open
phryneas
wants to merge
34
commits into
main
Choose a base branch
from
pr/textmate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d0098ce
minimal changes to inject new grammar into directives
phryneas 2637e5c
minimal (wrong) syntax highlighting for body & selection
phryneas 1ae4203
body...
phryneas 5e7f3dd
first attempt at jsonselection textmate grammar
phryneas 839a650
injection not working yet
phryneas 53c4a31
embed jsonselection as language
phryneas e4c6c87
some minor highlighting
phryneas 60814f7
change to new ebnf, start over
phryneas c30aaf4
progress
phryneas bda40e6
progress
phryneas d0d2c77
getting somewhere
phryneas ab78a30
JSONSelectionString
phryneas e20832b
add comments, snapshot tests
phryneas b1ff896
update one grammar, move things
phryneas 0ea12de
uncomment
phryneas 5b85408
flip some priorities
phryneas 51c573d
allow leading underscore in identifiers/keys/aliases
phryneas 39c29d2
allow PUT|PATCH|DELETE
phryneas 2a72811
split out connect-jsonselection-nested-argument, test
phryneas 8711cf3
add schema ref
phryneas 7c1fd89
fix: correct handling of nested objects
phryneas 1483930
special highlighting for `({` `})` bracket pairs
phryneas 073162f
fix typo
phryneas 4deca72
highlighting of `@`, `$.` and `$.foo`
phryneas 810cf1a
undo `{(` grouping
phryneas 5c2ea2f
set apart `{` in `JSONSelectionString` visually
phryneas 07b9f61
redo accidental wrong edit
phryneas f433e14
update snapshots, run more tests in CI
phryneas 304b70c
also write graphql.connectors with a yaml source
phryneas 5738e9a
rename scope according to recommendations
phryneas c84606b
rename things to "Apollo Connectors Mapping Syntax"
phryneas 4280f23
sort the language at the end of the list
phryneas 9c2ede1
reduce diff to original graphql grammar
phryneas ca52e1f
add comments to document injection logic
phryneas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"comments": { | ||
"lineComment": "#" | ||
}, | ||
"brackets": [ | ||
["[", "]"], | ||
["{", "}"], | ||
["(", ")"] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/__tests__/fixtures/textmate/test.apollo.jsonselection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Examples from https://github.com/apollographql/router/blob/next/apollo-federation/src/sources/connect/json_selection/README.md | ||
|
||
id | ||
name | ||
abc: some.nested.path { a b c } | ||
id | ||
name | ||
some.nested.path { a b c } | ||
names: { | ||
first: firstName | ||
last: lastName | ||
} | ||
# Also allowed: | ||
firstName | ||
lastName | ||
postID | ||
title | ||
author: { | ||
id: authorID | ||
name: authorName | ||
} | ||
title | ||
year: publication.year | ||
authorName: author.name | ||
id | ||
created | ||
model | ||
|
||
# The { role content } SubSelection is mandatory so the output keys | ||
# can be statically determined: | ||
choices->first.message { role content } | ||
|
||
# Multiple PathWithSubSelections are allowed in the same SubSelection: | ||
choices->last.message { lastContent: content } | ||
# For some reason /users/{$args.id} returns an object with name | ||
# and email but no id, so we inject the id manually: | ||
id: $args.id | ||
name | ||
id name friends: friend_ids { id: $ } | ||
items: data.nested.items { id name } | ||
firstItem: data.nested.items->first { id name } | ||
firstItemName: data.nested.items->first.name | ||
$.data { id name } | ||
id: data.id | ||
name: data.name | ||
all: $.first->and($.second)->and($.third) | ||
wrapped: field->echo({ fieldValue: @ }) | ||
children: parent->echo([@.child1, @.child2, @.child3]) | ||
doubled: numbers->map({ value: @->mul(2) }) | ||
types: values->map(@->typeof) | ||
__typename: $("Product") | ||
condition: $(true) | ||
alphabetSlice: $("abcdefghijklmnopqrstuvwxyz")->slice($args.start, $args.end) | ||
suffix: results.slice($(-1)->mul($args.suffixLength)) | ||
# The ->echo method returns its first input argument as-is, ignoring | ||
# the input data. Useful for embedding literal values, as in | ||
# $->echo("give me this string"), or wrapping the input value. | ||
__typename: $->echo("Book") | ||
wrapped: field->echo({ fieldValue: @ }) | ||
|
||
# Returns the type of the data as a string, e.g. "object", "array", | ||
# "string", "number", "boolean", or "null". Note that `typeof null` is | ||
# "object" in JavaScript but "null" for our purposes. | ||
typeOfValue: value->typeof | ||
|
||
# When invoked against an array, ->map evaluates its first argument | ||
# against each element of the array, binding the element values to `@`, | ||
# and returns an array of the results. When invoked against a non-array, | ||
# ->map evaluates its first argument against that value and returns the | ||
# result without wrapping it in an array. | ||
doubled: numbers->map(@->mul(2)) | ||
types: values->map(@->typeof) | ||
|
||
# Returns true if the data is deeply equal to the first argument, false | ||
# otherwise. Equality is solely value-based (all JSON), no references. | ||
isObject: value->typeof->eq("object") | ||
|
||
# Takes any number of pairs [candidate, value], and returns value for | ||
# the first candidate that equals the input data. If none of the | ||
# pairs match, a runtime error is reported, but a single-element | ||
# [<default>] array as the final argument guarantees a default value. | ||
__typename: kind->match( | ||
["dog", "Canine"], | ||
["cat", "Feline"], | ||
["Exotic"] | ||
) | ||
|
||
# Like ->match, but expects the first element of each pair to evaluate | ||
# to a boolean, returning the second element of the first pair whose | ||
# first element is true. This makes providing a final catch-all case | ||
# easy, since the last pair can be [true, <default>]. | ||
__typename: kind->matchIf( | ||
[@->eq("dog"), "Canine"], | ||
[@->eq("cat"), "Feline"], | ||
[true, "Exotic"] | ||
) | ||
|
||
# Arithmetic methods, supporting both integers and floating point values, | ||
# similar to JavaScript. | ||
sum: $.a->add($.b)->add($.c) | ||
difference: $.a->sub($.b)->sub($.c) | ||
product: $.a->mul($.b, $.c) | ||
quotient: $.a->div($.b) | ||
remainder: $.a->mod($.b) | ||
|
||
# Array/string methods | ||
first: list->first | ||
last: list->last | ||
index3: list->get(3) | ||
secondToLast: list->get(-2) | ||
slice: list->slice(0, 5) | ||
substring: string->slice(2, 5) | ||
arraySize: array->size | ||
stringLength: string->size | ||
|
||
# Object methods | ||
aValue: $->echo({ a: 123 })->get("a") | ||
hasKey: object->has("key") | ||
hasAB: object->has("a")->and(object->has("b")) | ||
numberOfProperties: object->size | ||
keys: object->keys | ||
values: object->values | ||
entries: object->entries | ||
keysFromEntries: object->entries.key | ||
valuesFromEntries: object->entries.value | ||
|
||
# Logical methods | ||
negation: $.condition->not | ||
bangBang: $.condition->not->not | ||
disjunction: $.a->or($.b)->or($.c) | ||
conjunction: $.a->and($.b, $.c) | ||
aImpliesB: $.a->not->or($.b) | ||
excludedMiddle: $.toBe->or($.toBe->not)->eq(true) | ||
|
||
# Tests from https://github.com/apollographql/router/blob/next/apollo-federation/src/sources/connect/url_template.rs | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this JSONSchema which somehow adds a tiny little bit of documentation to the textmate format.