Elentra API
  • Introduction
  • Developers
    • Getting Started
    • Quickstart Guide
      • Set up Repositories
      • Validate the setup
      • Exploring the API
      • Creating a new Module
      • Setup Routing
      • Introduction to Postman
      • Create a Controller
      • Using Eloquent Models
      • Input Validation
      • API Resource Authorization
  • Elentra API Standards
    • HTTP Methods & Status Codes
    • Routing & Parameters
      • Example Routing Patterns with HTTP Method
        • /courses/{course}/contacts
        • /courses/{course}/contacts?type={contact_type}
        • /courses/{course}/contacts/{contact}
        • /courses/{course}/syllabus
      • Common Mistakes
        • [GET] /admissions/file-review/file/rubric-score/{cycle_id}/{pool_id}/{subpool_id}
        • [DELETE] /notices/1,2,3
        • [GET] /cbe/curriculum/framework/{framework_id}/hierarchy-by-depth
        • [GET] /admissions/file-review/file/rubric-score/delete/{id}
        • [GET] /portfolio/entries/{entry_id}/get-file
        • [POST] /cbe/curriculum/updateframework
  • Automated Testing
    • Getting Started
      • Setting up a testing environment
      • Running Automated Tests
    • Seed Data
      • Folder Structure
      • Creating Seed Data
    • Functional Tests
      • Creating a Functional Test File
      • Testing HTTP Verbs
        • Creating an HTTP Test
        • GET Requests
        • POST / PUT / DELETE Requests
        • GraphQL Requests
      • Asserting API Response
      • Annotations
    • Code Style Linting
Powered by GitBook
On this page
  1. Automated Testing
  2. Functional Tests
  3. Testing HTTP Verbs

GraphQL Requests

GraphQL Requests

When testing a GraphQL endpoint, we set the $schema property on the test class.

/**
 * @var string the GraphQL schema name
 */
protected $schema = 'sandboxes';

The mutation must be stored in a variable for readability in each test.

public function sandboxes_save_object_returns_200(): void
{
    $mutation = <<<'GQL'
    mutation {
        saveSandbox(data: { title: "New Sandbox" }) {
            id
            title
        }
    }
    GQL;
    
    // ...
}

To run the GraphQL endpoint, call the ->graphql() method.

public function sandboxes_save_object_returns_200(): void
{
    $mutation = <<<'GQL'
    mutation {
        saveSandbox(data: { title: "New Sandbox" }) {
            id
            title
        }
    }
    GQL;

    $this->actingAsAdmin()
        ->authenticate()
      	->graphql($mutation);
}
PreviousPOST / PUT / DELETE RequestsNextAsserting API Response

Last updated 2 years ago