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

feat: Adding ability to import postman graphql collections #807

Merged

Conversation

vaugenwake
Copy link
Contributor

Fixes: #790

Description

This PR adds functionality to import a GraphQL collection exported from Postman client into Bruno.

Changes:

  1. Add function parseGraphQLQuery() to parse and clean incoming GraphQL queries from postman collection
  2. Add function parseGraphQLVariables() to parse and clean incoming GraphQL variables
  3. Add function parseGraphQLRequest() to handle validating incoming data and keys

This PR check the mode of the request item in the collection to then trigger a GraphQL sanitisation and build a valid request to be input into Bru format.

Testing:

Source Sample Collection:

{
    "info": {
        "_postman_id": "c33bffc4-0e32-498b-a12d-2b5d54eebf14",
        "name": "Test Stub Graphql",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "item": [
        {
            "name": "Get Countries",
            "id": "0e7a0dfa-9c23-40af-8a78-a102c63dc873",
            "protocolProfileBehavior": {
                "disableBodyPruning": true
            },
            "request": {
                "method": "POST",
                "header": [],
                "body": {
                    "mode": "graphql",
                    "graphql": {
                        "query": "query Countries {\n    countries {\n        awsRegion\n        capital\n        code\n        currencies\n        currency\n        emoji\n        emojiU\n        name\n        native\n        phone\n        phones\n    }\n}",
                        "variables": ""
                    }
                },
                "url": {
                    "raw": "https://countries.trevorblades.com",
                    "protocol": "https",
                    "host": [
                        "countries",
                        "trevorblades",
                        "com"
                    ]
                }
            },
            "response": []
        },
        {
            "name": "Get Country",
            "id": "5c13fa4e-5755-4acd-b4fe-9fb7fd9dd96b",
            "protocolProfileBehavior": {
                "disableBodyPruning": true
            },
            "request": {
                "method": "POST",
                "header": [],
                "body": {
                    "mode": "graphql",
                    "graphql": {
                        "query": "query GetCountry($code: ID!) {\n    country(code: $code) {\n        awsRegion\n        capital\n        code\n        currencies\n        currency\n        emoji\n        emojiU\n        name\n        native\n        phone\n        phones\n    }\n}",
                        "variables": "{\n    \"code\": \"ZA\"\n}"
                    }
                },
                "url": {
                    "raw": "https://countries.trevorblades.com",
                    "protocol": "https",
                    "host": [
                        "countries",
                        "trevorblades",
                        "com"
                    ]
                }
            },
            "response": []
        }
    ]
}

Bru Collection Results

Get Countries:

meta {
  name: Get Countries
  type: graphql
  seq: 1
}

post {
  url: https://countries.trevorblades.com
  body: graphql
  auth: none
}

body:graphql {
  query Countries{countries{awsRegion capital code currencies currency emoji emojiU name native phone phones}}
}

Get Country:

meta {
  name: Get Country
  type: graphql
  seq: 2
}

post {
  url: https://countries.trevorblades.com
  body: graphql
  auth: none
}

body:graphql {
  query GetCountry($code: ID!){country(code: $code){awsRegion capital code currencies currency emoji emojiU name native phone phones}}
}

body:graphql:vars {
  {"code":"ZA"}
}

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

@vaugenwake
Copy link
Contributor Author

vaugenwake commented Oct 26, 2023

@helloanoop I have taken a stab at getting this implemented. I would like to hear your comments. I have done some testing (as outlined above), but there might still be work to validate all use cases I missed.

@helloanoop helloanoop merged commit fa8ec42 into usebruno:main Oct 29, 2023
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

Successfully merging this pull request may close these issues.

[Bug] When importing Postman collections, graphql requests are not imported correctly
3 participants