graphql.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Language: GraphQL
  3. Author: John Foster (GH jf990), and others
  4. Description: GraphQL is a query language for APIs
  5. Category: web, common
  6. */
  7. /** @type LanguageFn */
  8. function graphql(hljs) {
  9. const regex = hljs.regex;
  10. const GQL_NAME = /[_A-Za-z][_0-9A-Za-z]*/;
  11. return {
  12. name: "GraphQL",
  13. aliases: [ "gql" ],
  14. case_insensitive: true,
  15. disableAutodetect: false,
  16. keywords: {
  17. keyword: [
  18. "query",
  19. "mutation",
  20. "subscription",
  21. "type",
  22. "input",
  23. "schema",
  24. "directive",
  25. "interface",
  26. "union",
  27. "scalar",
  28. "fragment",
  29. "enum",
  30. "on"
  31. ],
  32. literal: [
  33. "true",
  34. "false",
  35. "null"
  36. ]
  37. },
  38. contains: [
  39. hljs.HASH_COMMENT_MODE,
  40. hljs.QUOTE_STRING_MODE,
  41. hljs.NUMBER_MODE,
  42. {
  43. scope: "punctuation",
  44. match: /[.]{3}/,
  45. relevance: 0
  46. },
  47. {
  48. scope: "punctuation",
  49. begin: /[\!\(\)\:\=\[\]\{\|\}]{1}/,
  50. relevance: 0
  51. },
  52. {
  53. scope: "variable",
  54. begin: /\$/,
  55. end: /\W/,
  56. excludeEnd: true,
  57. relevance: 0
  58. },
  59. {
  60. scope: "meta",
  61. match: /@\w+/,
  62. excludeEnd: true
  63. },
  64. {
  65. scope: "symbol",
  66. begin: regex.concat(GQL_NAME, regex.lookahead(/\s*:/)),
  67. relevance: 0
  68. }
  69. ],
  70. illegal: [
  71. /[;<']/,
  72. /BEGIN/
  73. ]
  74. };
  75. }
  76. export { graphql as default };