Getting the string graphql in my grapiql playground

Hello, I’ve been trying to find a way to get the full string query that is written in the Graphql playground.

Every query and mutation works as it should.
Through my code I want to get the string of the query that is to be executed.
Example of a variable in my code that stores the query:

query = 
"""
{
  authors{
    id
    comments{
      id
    }
  }
}
"""

Get where? The string is printed in the logs if you’re just trying to be able to copy and paste it.

I’m trying to store it in a variable in my code. I can see it being printed in my logs for know but I want to manipulate that string inside my code when executed.

There are some options, but can you first elaborate on what you’re trying to do? In general you shouldn’t need to worry about the exact GraphQL string being supplied.

I want to calculate the deepness of my query and limit the maximum depth to 4. The purpose is to secure my app from queries like:

query IAmEvil {
  author(id: "abc") {
    posts {
      author {
        posts {
          author {
            posts {
              author {
                # that could go on as deep as the client wants!
              }
            }
          }
        }
      }
    }
  }   
}

Good news! A feature like this already exists: https://hexdocs.pm/absinthe/complexity-analysis.html#content

4 Likes