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

Allow GraphQL request body to be a file path #24

Open
benjamin-rood opened this issue Mar 11, 2020 · 2 comments
Open

Allow GraphQL request body to be a file path #24

benjamin-rood opened this issue Mar 11, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@benjamin-rood
Copy link

benjamin-rood commented Mar 11, 2020

At the moment it seems like only binary content can be provided as a file path.

For some requests, e.g. GraphQL to properly check coverage, the query might be > 1000 lines, and the schema might cover 100s of Query and Mutation endpoints. It's completely impractical to paste the raw query in every single spec file.

Using the example from the readme:

meta:
  name: GraphQL location service
configuration:
  host: api.graphloc.com
  scheme: https
specs:
  - name: Get Location of a given ip address
    request:
      method: post
      path: /graphql
      headers:
        - name: content-type
          value: application/json
      payload:
        body:
          type: json
          content:
            query: >
                   {
                    getLocation(ip: "8.8.8.8") {
                      country {
                        iso_code
                      }
                     }
                    }
            variables: null
            operationName: null
    response:
      status_code: 200
      json_data:
        - path: $.data.getLocation.country.iso_code
          value: US

It would be very useful for payload.body.content.query to be a file path rather than an inline query.

@kiranz kiranz added the enhancement New feature or request label Mar 13, 2020
Repository owner deleted a comment from amkiran Mar 14, 2020
@kiranz
Copy link
Owner

kiranz commented Mar 14, 2020

@benjamin-rood That's a good feature to have. Adding it to backlog.

Meanwhile, you can still read request payload from JSON files as done below
Note: CustomRequire and CustomPath are regular js require and path modules exported in c.js which runs as part of configuration of a suite.

meta:
   name: POST raw body requests (json , text, binary )
configuration:
  custom_configuration:
    run_type: module
    module:
      module_path: ./c.js
      function_name: main  
specs:
  - name: JSON data (file) as body
    before_test:
      run_type: inline
      inline:
        function: !!js/function >
          function() {
            const payload = CustomRequire(CustomPath.resolve(process.cwd(), "p.json"));
            this.test.payload = {body: {type: 'json', content: payload}};            
          }     
    request:
      path: /echoBinaryBodyResponseStats
      method: post
      headers:
        - name: content-type
          value: application/json
    response:
      status_code: 200
      json_data:
        - path: $.request_content_size
          value: 12371

c.js

"use strict";


global.CustomRequire = require;
global.CustomPath = require("path");



function main() {
  this.scheme = "http";
  this.host = "127.0.0.1";
  this.port = 3027;
}

module.exports = {
  main
};

@benjamin-rood
Copy link
Author

Thanks, @kiranz I will make use of this approach in the mean time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants