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

Fixing unintended update to GraphQL operation when updating REST methods #1555

Merged
merged 215 commits into from
Jul 5, 2023

Conversation

severussundar
Copy link
Contributor

@severussundar severussundar commented Jun 28, 2023

Why make this change?

  1. Creating a stored procedure entity with graphql configured for Query

Command: dab add getbooks --source "get_books" --source.type "stored-procedure" --permissions "anonymous:execute" --graphql.operation "query"
Config Json (just the entities section):

 "entities": {
    "getbooks": {
  "source": {
    "object": "get_books",
    "type": "stored-procedure",
    "parameters": null,
    "key-fields": null
  },
  "graphql": {
    "enabled": true,
    "operation": "query",
    "type": {
      "singular": "getbooks",
      "plural": "getbooks"
    }
  },
  "rest": {
    "enabled": true,
    "path": null,
    "methods": [
      "post"
    ]
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        {
          "action": "execute",
          "fields": null,
          "policy": {
            "request": null,
            "database": null
          }
        }
      ]
    }
  ],
  "mappings": null,
  "relationships": null
}
  }
  1. Update the rest method to GET
    Command: dab update getbooks --rest.methods "GET"

Config Json:

"entities": {
    "getbooks": {
  "source": {
    "object": "get_books",
    "type": "stored-procedure",
    "parameters": null,
    "key-fields": null
  },
  "graphql": {
    "enabled": true,
    "operation": "mutation",
    "type": {
      "singular": "getbooks",
      "plural": "getbooks"
    }
  },
  "rest": {
    "enabled": true,
    "path": null,
    "methods": [
      "get"
    ]
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        {
          "action": "execute",
          "fields": null,
          "policy": {
            "request": null,
            "database": null
          }
        }
      ]
    }
  ],
  "mappings": null,
  "relationships": null
}
  }

When updating the rest.methods, the graphql operation has lost its original value of query. It now has the default value of mutation.

What is this change?

  • ConfigGenerator.ConstructUpdatedGraphQLDetails(): When GraphQL operation is not updated, logic for preserving the existing configured graphQL operation is added
  • EndToEndTests.TestUpdatingStoredProcedureWithRestMethods(): Adds a test case with the mentioned repro steps

How was this tested?

  • Unit Tests
  • Manual Tests

Sample Request(s)

  • dab add getbooks --source "getbooks" --source.type "stored-procedure" --permissions "anonymous:execute" --graphql.operation "query"
 "entities": {
    "getbooks": {
  "source": {
    "object": "getbooks",
    "type": "stored-procedure",
    "parameters": null,
    "key-fields": null
  },
  "graphql": {
    "enabled": true,
    "operation": "query",
    "type": {
      "singular": "getbooks",
      "plural": "getbooks"
    }
  },
  "rest": {
    "enabled": true,
    "path": null,
    "methods": [
      "post"
    ]
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        {
          "action": "execute",
          "fields": null,
          "policy": {
            "request": null,
            "database": null
          }
        }
      ]
    }
  ],
  "mappings": null,
  "relationships": null
}
  }
  • dab update getbooks --rest.methods "get,patch"
 "entities": {
    "getbooks": {
  "source": {
    "object": "getbooks",
    "type": "stored-procedure",
    "parameters": null,
    "key-fields": null
  },
  "graphql": {
    "enabled": true,
    "operation": "query",
    "type": {
      "singular": "getbooks",
      "plural": "getbooks"
    }
  },
  "rest": {
    "enabled": true,
    "path": null,
    "methods": [
      "get",
      "patch"
    ]
  },
  "permissions": [
    {
      "role": "anonymous",
      "actions": [
        {
          "action": "execute",
          "fields": null,
          "policy": {
            "request": null,
            "database": null
          }
        }
      ]
    }
  ],
  "mappings": null,
  "relationships": null
}

The rest.methods field is updated with the right values and the existing value of graphql.operation is preserved

Finding missing types
Refactoring some type names
Simplifying the GraphQL naming by doing that when building the config, rather than on demand
Added implementation of JsonConverter.Write methods to generate an initial pass on the config file using CLI
Removed some tests that weren't testing the CLI but dependencies (such as CommandLineParser or ILogger)
…them simpler and clearer with the new object structure
Moved logic for Entities defaults to RuntimeEntities rather than deserialiser, as that is a more logical place. We always pass that type around, so we can assume the ctor ran, but we aren't always assuming the deserialiser ran (such as what happens with tests)
Copy link
Contributor

@aaronpowell aaronpowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Waiting for the tests to pass.

I like that we have another Verify test in there!

@severussundar severussundar self-assigned this Jul 4, 2023
@severussundar severussundar added this to the 0.8 milestone Jul 4, 2023
@severussundar severussundar merged commit aa5c8a3 into main Jul 5, 2023
@severussundar severussundar deleted the dev/shyamsundarj/bugfix-update-rest-methods branch July 5, 2023 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating rest methods leads to an update to grapql operations
3 participants