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

Do not prompt for confirmation for GraphQL queries without a mutation #39

Open
gr2m opened this issue Apr 23, 2021 · 1 comment
Open
Assignees

Comments

@gr2m
Copy link
Member

gr2m commented Apr 23, 2021

Sending a GraphQL query is currently a POST /graphql request, so even if the query does not perform any mutation, the CLI is prompting the user to confirm the request

? Do you want to allow the following request:

  <unknown endpoint>
  route:     POST /graphql
  query:     query($htmlUrl: URI!) {
      resource(url: $htmlUrl) {
        ... on PullRequest {
          state
          author {
            login
          }
          files(first:2) {
            nodes {
              path
            }
          }
          commits(last: 1) {
            nodes {
              commit {
                oid
                checkSuites(first: 100) {
                  nodes {
                    checkRuns(first: 100) {
                      nodes {
                        name
                        conclusion
                        permalink
                      }
                    }
                  }
                }
                status {
                  state
                  contexts {
                    state
                    targetUrl
                    description
                    context
                  }
                }
              }
            }
          }
        }
      }
    }
  variables: [object Object]
 … 
❯ yes
  no
  yes, for all "POST /graphql" requests
  yes, for all requests
@gr2m gr2m self-assigned this Apr 23, 2021
@gr2m
Copy link
Member Author

gr2m commented Apr 23, 2021

They way to go will be to use graphql-tag to turn the query into an AST, then check if the query includes a mutation

const gql = require("graphql-tag");
const ast = gql(query);
const queryHasMutation = ast.definitions.filter(({ operation }) => operation === "mutation");

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

1 participant