open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.76k stars 1.36k forks source link

graphql.parse(query, schema) no longer returns definition as part of the query ast #6829

Open kroekle opened 5 months ago

kroekle commented 5 months ago

Short description

The graphql.parse(query, schema) builtin that was added in v0.41 no longer returns definition as part of the query ast had return the property definition as port of the query_ast that was returned from the call. Versions prior to v0.45.0 the definition property, versions >= v0.45.0 do not. (seems like a library upgrade is the source of this change)

Steps To Reproduce

Sample input:

{
  "schema": "type Employee {id: String! salary: Int!} schema { query: Query} type Query {employeeByID(id: String!): Employee}",
  "query": "query { employeeByID(id: \"alice\") { salary }}"
}

Sample policy: `package gql

ast := graphql.parse(input.query, input.schema)[0]`

Docker commands: docker run -it -v $(pwd)/.:/sample openpolicyagent/opa:0.44.0 eval -d /sample -i /sample/input.json data.gql.ast docker run -it -v $(pwd)/.:/sample openpolicyagent/opa:0.45.0 eval -d /sample -i /sample/input.json data.gql.ast

Expected behavior

Current output:

{
  "result": [
    {
      "expressions": [
        {
          "value": {
            "Operations": [
              {
                "Name": "",
                "Operation": "query",
                "SelectionSet": [
                  {
                    "Alias": "employeeByID",
                    "Arguments": [
                      {
                        "Name": "id",
                        "Value": {
                          "Kind": 3,
                          "Raw": "alice"
                        }
                      }
                    ],
                    "Name": "employeeByID",
                    "SelectionSet": [
                      {
                        "Alias": "salary",
                        "Name": "salary"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          "text": "data.gql.ast",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}

Expected output:

{
  "result": [
    {
      "expressions": [
        {
          "value": {
            "Operations": [
              {
                "Name": "",
                "Operation": "query",
                "SelectionSet": [
                  {
                    "Alias": "employeeByID",
                    "Arguments": [
                      {
                        "Name": "id",
                        "Value": {
                          "Definition": {
                            "BuiltIn": true,
                            "Description": "The `String`scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.",
                            "Kind": "SCALAR",
                            "Name": "String"
                          },
                          "ExpectedType": {
                            "NamedType": "String",
                            "NonNull": true
                          },
                          "Kind": 3,
                          "Raw": "alice"
                        }
                      }
                    ],
                    "Definition": {
                      "Arguments": [
                        {
                          "Description": "",
                          "Name": "id",
                          "Type": {
                            "NamedType": "String",
                            "NonNull": true
                          }
                        }
                      ],
                      "Description": "",
                      "Name": "employeeByID",
                      "Type": {
                        "NamedType": "Employee",
                        "NonNull": false
                      }
                    },
                    "Name": "employeeByID",
                    "ObjectDefinition": {
                      "BuiltIn": false,
                      "Description": "",
                      "Fields": [
                        {
                          "Arguments": [
                            {
                              "Description": "",
                              "Name": "id",
                              "Type": {
                                "NamedType": "String",
                                "NonNull": true
                              }
                            }
                          ],
                          "Description": "",
                          "Name": "employeeByID",
                          "Type": {
                            "NamedType": "Employee",
                            "NonNull": false
                          }
                        },
                        {
                          "Description": "",
                          "Name": "__schema",
                          "Type": {
                            "NamedType": "__Schema",
                            "NonNull": true
                          }
                        },
                        {
                          "Arguments": [
                            {
                              "Description": "",
                              "Name": "name",
                              "Type": {
                                "NamedType": "String",
                                "NonNull": true
                              }
                            }
                          ],
                          "Description": "",
                          "Name": "__type",
                          "Type": {
                            "NamedType": "__Type",
                            "NonNull": false
                          }
                        }
                      ],
                      "Kind": "OBJECT",
                      "Name": "Query"
                    },
                    "SelectionSet": [
                      {
                        "Alias": "salary",
                        "Definition": {
                          "Description": "",
                          "Name": "salary",
                          "Type": {
                            "NamedType": "Int",
                            "NonNull": true
                          }
                        },
                        "Name": "salary",
                        "ObjectDefinition": {
                          "BuiltIn": false,
                          "Description": "",
                          "Fields": [
                            {
                              "Description": "",
                              "Name": "id",
                              "Type": {
                                "NamedType": "String",
                                "NonNull": true
                              }
                            },
                            {
                              "Description": "",
                              "Name": "salary",
                              "Type": {
                                "NamedType": "Int",
                                "NonNull": true
                              }
                            }
                          ],
                          "Kind": "OBJECT",
                          "Name": "Employee"
                        }
                      }
                    ]
                  }
                ]
              }
            ]
          },
          "text": "data.gql.ast",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}
stale[bot] commented 4 months ago

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.