From d46d511cd8872c3be5d48083029d215090c88307 Mon Sep 17 00:00:00 2001 From: Stefan Maric Date: Mon, 4 Mar 2019 09:08:15 +0100 Subject: [PATCH] Add GraphQL support (#306) * Add GraphQL support * Fix line count on Graphql test file * Add extra final new line to GraphQL test file * Fix line counts on graphql test file * Fix typo on graphql test file --- languages.json | 14 +++++++ tests/data/graphql.gql | 89 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/data/graphql.gql diff --git a/languages.json b/languages.json index 2208f5f..3c98768 100644 --- a/languages.json +++ b/languages.json @@ -636,6 +636,20 @@ "go" ] }, + "Graphql":{ + "name":"GraphQL", + "quotes":[ + ["\\\"", "\\\""], + ["\\\"\\\"\\\"", "\\\"\\\"\\\""] + ], + "line_comment":[ + "#" + ], + "extensions":[ + "gql", + "graphql" + ] + }, "Groovy":{ "base":"c", "extensions":[ diff --git a/tests/data/graphql.gql b/tests/data/graphql.gql new file mode 100644 index 0000000..c8b7050 --- /dev/null +++ b/tests/data/graphql.gql @@ -0,0 +1,89 @@ +# 89 lines 71 code 3 comments 15 blanks + +""" +A simple GraphQL schema which is well described. This is not a comment. +See: https://facebook.github.io/graphql/June2018/#sec-Descriptions +""" +type Query { + """ + Translates a string from a given language into a different language. + """ + translate( + "The original language that `text` is provided in." + fromLanguage: Language + + "The translated language to be returned." + toLanguage: Language + + "The text to be translated." + text: String + ): String +} + +""" +The set of languages supported by `translate`. +""" +enum Language { + "English" + EN + + "French" + FR + + "Chinese" + CH +} + +# Comment the query and use "quotes" inside the comment +query withFragments($expandedInfo: Boolean) { + user(id: "3bd5a1cbed10e") { + id # Insignificant comment + + ... @include(if: $expandedInfo) { + firstName + lastName + birthday + } + + friends(first: 10) { + ...friendFields + } + + profiles( + handles: [ + "zuck", + "cocacola", + "#hashed#hash#inside" + ] + ) { + handle + + ... on User { + friends { + count + } + } + + ... on Page { + likers { + count + } + } + } + } +} + +fragment friendFields on User { + id + firstName + profilePic(size: 50) +} + +# A simple GraphQL type definition +type User { + id: ID + firstName: String + lastName: String + birthday: Date +} +