Skip to content
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

Proposal - add a GRAPHQL sigil #1284

Open
dkuku opened this issue Nov 14, 2023 · 1 comment
Open

Proposal - add a GRAPHQL sigil #1284

dkuku opened this issue Nov 14, 2023 · 1 comment

Comments

@dkuku
Copy link

dkuku commented Nov 14, 2023

I have not seen this anywhere in requests but by adding a GRAPHQL sigil, this way we can use the formatter to format inline queries and also tree sitter can be setup for highlighting inline queries.
Example: https://maartenvanvliet.nl/2022/01/26/absinthe_formatter/

@oliver-kriska
Copy link

fyi I did it in our project:

defmodule GSigil do
  def sigil_G(string, []), do: string
end

somewhere where you want to use it

import GSigil

and plugin for formatter

defmodule GqlFormatter do
  @behaviour Mix.Tasks.Format

  def features(_opts) do
    [sigils: [:G]]
  end

  def format(contents, _opts \\ []) do
    Absinthe.Formatter.format(%Absinthe.Blueprint{input: contents})
  end
end

add plugin to formatter

 plugins: [GqlFormatter]

Usage

@cart_query_end_user ~G"""
  query cart {
    cart {
      id
      type
      totals {
        amountToPay {
          amount
          currency
        }
      }
      user {
        email
      }
      userId
      sessionUid
      items {
        id
        type
        productId
        productVersionId
        productVariantId
        productVariantVersionId
        quantity
      }
    }
  }
  """

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

No branches or pull requests

2 participants