How to find out GET request type from GraphQL in ASP.NET Core Web API with C#?

In GraphQL, all queries are sent using the HTTP POST method, regardless of whether they are “fetch” (GET) or “modify” (POST) operations. This is because GraphQL has its own query language and request format that doesn’t conform to the traditional RESTful API style.

To differentiate between a fetch (GET) or a modify (POST) operation in GraphQL, you can look at the content of the query that is being sent in the request body.

For example, in a typical GraphQL query, you might see something like this:

Copy code
query {
  getUser(id: 123) {
    name
    email
  }
}

This is a fetch (GET) operation that retrieves data from the server. On the other hand, a modify (POST) operation might look like this:

mutation {
  updateUser(id: 123, input: { name: "John", email: "john@example.com" }) {
    name
    email
  }
}

This is a modify (POST) operation that updates data on the server.

So, by looking at the content of the query being sent in the request body, you can determine whether it is a fetch or modify operation, even though both types of operations use the HTTP POST method in GraphQL.

Read more here: Source link