2022-08-04 01:12:52 +02:00
#+title : :lang graphql
#+subtitle : Give queries a REST
#+created : March 31, 2022
#+since : 22.04.0 (#6226)
* Description :unfold:
2022-03-31 08:28:43 +01:00
This module adds [[https://www.graphql.org ][GraphQL ]] support to Doom Emacs.
2022-08-04 01:12:52 +02:00
It includes:
- Code completion
2022-09-26 02:19:42 +08:00
- LSP support ([[doom-module:+lsp ]])
2022-08-04 01:12:52 +02:00
- Diagnostics (GraphQL syntax linting/validations) (spec-compliant)
- Autocomplete suggestions (spec-compliant)
- Hyperlink to fragment definitions and named types (type, input, enum) definitions (spec-compliant)
- Outline view support for queries and SDL
- Symbols support across the workspace
- Local schema viewer
2022-09-26 02:19:42 +08:00
- Org-babel exporter (requires [[doom-module::lang org ]])
2022-03-31 08:28:43 +01:00
** Maintainers
2022-08-04 01:12:52 +02:00
- [[doom-user: ][@elken ]]
[[doom-contrib-maintainer: ][Become a maintainer? ]]
2022-03-31 08:28:43 +01:00
2022-08-04 01:12:52 +02:00
** Module flags
- +lsp ::
2022-09-26 02:19:42 +08:00
Enable LSP support for ~graphql-mode~ . Requires [[doom-module::tools lsp ]] and a langserver
2022-08-04 01:12:52 +02:00
([[https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme ][graphql-language-service-cli ]]).
2022-03-31 08:28:43 +01:00
2022-08-04 01:12:52 +02:00
** Packages
2022-09-26 02:19:42 +08:00
- [[doom-package:company-graphql ]] unless [[doom-module:+lsp ]]
- [[doom-package:graphql-mode ]]
- [[doom-package:graphql-doc ]]
2022-03-31 08:28:43 +01:00
** Hacks
2022-09-26 02:19:42 +08:00
- Added a convenience function [[fn:+graphql-doc-open-config ]] to open schema docs from
2022-08-04 01:12:52 +02:00
a [[https://github.com/jimkyndemeyer/graphql-config-examples ][.graphqlconfig ]] file.
** TODO Changelog
# This section will be machine generated. Don't edit it by hand.
/This module does not have a changelog yet./
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338 ][Enable this module in your ~doom!~ block. ]]
2022-03-31 08:28:43 +01:00
2022-11-19 09:38:26 +00:00
** LSP
2022-08-04 01:12:52 +02:00
This module has no direct requirements, but the +lsp flag requires a [[https://emacs-lsp.github.io/lsp-mode/page/lsp-graphql/ ][supported
LSP server]].
2022-03-31 08:28:43 +01:00
2022-11-19 09:38:26 +00:00
** Formatter
Formatting is handled using the [[doom-module::editor format ]] module via [[https://prettier.io/docs/en/install.html ][prettier ]].
2022-08-04 01:12:52 +02:00
* Usage
2022-03-31 08:28:43 +01:00
** Sending queries
When visiting a graphql buffer, you have access to the ability to send the
current query with =C-c C-c= which will prompt you for an optional variables file,
then execute the query and return a buffer of the results.
It's also possible to send queries using org-babel using a block such as the
ones below (executing correctly will require =:lang org= )
#+NAME : my-variables
#+begin_src json
{
"continentCode": "AF"
}
#+end_src
#+BEGIN_SRC graphql :url https://countries.trevorblades.com/ :variables my-variables
query GetContinents($continentCode: String!) {
continent(code: $continentCode) {
name
code
}
}
#+END_SRC
#+RESULTS :
: {
: "data": {
: "continent": {
: "name": "Africa",
: "code": "AF"
: }
: }
: }
** Viewing docs
With this module, there are 3 ways to view schemas:
+ =+graphql-doc-open-config= which uses a local [[https://github.com/jimkyndemeyer/graphql-config-examples ][=.graphqlconfig= ]] file to seed endpoints to query
+ =graphql-doc= which prompts you to select an endpoint based on ones added manually by =graphql-doc-add-api=
2024-04-02 01:30:10 +08:00
+ =graphql-doc-open-url= which prompts to manually enter an endpoint url
2022-03-31 08:28:43 +01:00
When using the doc viewer, there are a few bindings for navigating around.
| Key | Command | Description |
|-------------+---------------------+-----------------------------------|
| =C-j= | =forward-button= | Follow a forward button |
| =C-k= | =backward-button= | Follow a backward button |
| =<backspace>= | =graphql-doc-go-back= | Go back to a previous page |
| =mouse-1= | - | Follow the next label under =point= |
| =RET= | - | Follow the next label under =point= |
* Configuration
2022-08-04 01:12:52 +02:00
Most of the "magic" in the module relies on a properly configured [[https://github.com/jimkyndemeyer/graphql-config-examples ][.graphqlconfig ]]
file, so follow the examples linked to create an appropriate setup.
2022-03-31 08:28:43 +01:00
2022-08-04 01:12:52 +02:00
LSP configuration is handled through [[https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#graphql-configuration-file-graphqlrcyml ][GraphQL Config ]] to handle custom
directives/documents/validation etc.
2022-03-31 08:28:43 +01:00
2022-08-04 01:12:52 +02:00
These files will also be useful to other editors, so it would be worth checking
them into version control.
2022-03-31 08:28:43 +01:00
* Troubleshooting
2022-08-04 01:12:52 +02:00
[[doom-report: ][Report an issue? ]]
2022-03-31 08:28:43 +01:00
- [[https://github.com/ifitzpatrick/graphql-doc.el/issues ][Issues with the doc viewer ]]
- [[https://github.com/davazp/graphql-mode/issues ][Issues with graphql-mode ]]
- [[https://github.com/emacs-lsp/lsp-mode/issues ][Issues with LSP ]] ([[https://github.com/graphql/graphiql/issues ][Upstream LSP issues ]])
2022-08-04 01:12:52 +02:00
* Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq: ][Ask one? ]]
* TODO Appendix
#+begin_quote
2023-09-16 20:19:11 +02:00
This module has no appendix yet. [[doom-contrib-module: ][Write one? ]]
2022-08-04 01:12:52 +02:00
#+end_quote