GraphQL Tooling in PhpStorm for Magento and General APIs
AI generated
IDE
{ }
PhpStorm · GraphQL · Magento 2 · API Development
GraphQL Tooling in PhpStorm:
Schema, HTTP Client and Introspection

Writing GraphQL queries without schema autocompletion means keeping field names in your head and only seeing errors at runtime. PhpStorm with the GraphQL plugin validates queries statically against the schema, completes fields and arguments, and lets you fire HTTP requests directly from the IDE, without Postman or a browser devtool.

14 min read GraphQL · Schema · Introspection · HTTP Client · Magento 2 PhpStorm 2024.x · GraphQL plugin · Magento 2.4.x

1. Why GraphQL tooling in the IDE matters

GraphQL is a strongly typed protocol: every query, every mutation and every subscription event has an exact type signature defined by the schema. Making this type information available at development time is the core benefit of IDE tooling. Anyone writing a products query against the Magento GraphQL API who doesn't know whether the thumbnail field sits inside small_image or directly under image has to guess, dig through documentation, or start a trial-and-error cycle without tooling support.

With the GraphQL plugin in PhpStorm, the full field list, complete with types and descriptions, appears directly as autocompletion in the editor. Invalid field names are underlined immediately, missing required arguments are flagged as errors, and a field's type is visible on hover. This reduces context switching between documentation, browser tools and the IDE to zero, keeping the entire development flow inside a single environment.

This matters especially for Magento 2: the Magento GraphQL API has a very extensive schema with hundreds of types, nested structures and module-dependent field extensions. Without autocompletion, navigating this schema is time-consuming and error-prone. The GraphQL plugin makes the entire API surface directly accessible right in the editor.

2. Installing and configuring the GraphQL plugin

The GraphQL plugin is bundled by default in PhpStorm 2023.x and newer. In older versions, you can find it via Settings → Plugins → Marketplace by searching for "GraphQL". After installation, a configuration file, either .graphqlconfig or graphql.config.yml, needs to be created in the project root that tells the plugin where to find the schema, either as a local SDL file or as a URL for introspection.

The configuration for a Magento project typically looks like this: the schema URL points to the local development server (http://localhost/graphql), introspection is authenticated with an optional bearer token, and the file patterns define which .graphql and .gql files in the project should be recognized as GraphQL. PhpStorm shows in the editor status bar whether the schema was loaded successfully and when it was last refreshed.

3. Loading the schema via introspection

Introspection is the mechanism that lets GraphQL clients query a server's complete schema, including all types, fields, arguments and descriptions. PhpStorm uses this feature to automatically load the schema from the running Magento server, without having to manually maintain a separate SDL file. The advantage: the schema in the editor always matches exactly what the server actually offers, including all module-specific extensions.

After loading the schema via introspection, PhpStorm caches it locally in the project. This means autocompletion is available even without a running server, for example when writing queries in offline mode or in the CI pipeline. When the schema changes (for instance after installing a new Magento module that extends the GraphQL API), the schema can be reloaded with a single click on "Refresh Schema".


# graphql.config.yml (PhpStorm GraphQL configuration for Magento 2)
# Place in project root alongside composer.json

schema:
  - ./src/vendor/magento/module-catalog-graph-ql/etc/schema.graphqls
  - ./src/app/code/**/*.graphqls

documents:
  - ./src/app/design/**/*.graphql
  - ./src/app/code/**/*.graphql

extensions:
  endpoints:
    local:
      url: http://magento.local/graphql
      headers:
        Content-Type: application/json
        Authorization: "Bearer ${MAGENTO_ADMIN_TOKEN}"
    staging:
      url: https://staging.mironsoft.de/graphql
      headers:
        Content-Type: application/json
        Authorization: "Bearer ${STAGING_ADMIN_TOKEN}"

4. Autocompletion and inline validation

Once the schema is loaded, autocompletion activates in .graphql files. As you type a field name, a dropdown list of all available fields on the current type appears, complete with type annotation and the description taken from the schema. Arguments are completed as well, including whether they're required or optional, and allowed values for enum types. Navigating between nested types works with Ctrl+Click on any type name; PhpStorm jumps straight to the type definition in the SDL file.

Inline validation checks in real time: fields that don't exist in the schema are marked with a red underline. Missing required arguments show a warning. Type errors, for example when a string argument receives an int value, are visible immediately. This static analysis catches the most common GraphQL mistakes before the query is even sent to the server, saving the full request-response round trip for every typo.

5. HTTP client for GraphQL queries

PhpStorm's built-in HTTP client natively supports GraphQL, no external application like Postman or Insomnia needed. In a .http file, a GraphQL query can be executed directly with the content type application/json and a JSON body. The result appears in the same editor window, formatted as a collapsible JSON tree.

The advantage over external tools: .http files are versioned and live in the repository. The whole team shares the same test queries, mutations and variables. Environment variables (tokens, base URLs) are stored in .env files and are substituted automatically when the request runs. This makes testing a Magento GraphQL mutation with real test data a 30-second job, without leaving the IDE or maintaining a separate configuration.


### Magento 2 GraphQL: Product Query
### File: tests/graphql/product-queries.http
### Variables loaded from: http-client.env.json

POST {{magento_base_url}}/graphql
Content-Type: application/json

{
  "query": "query GetProduct($sku: String!) { products(filter: { sku: { eq: $sku } }) { items { id name sku price_range { minimum_price { regular_price { value currency } } } small_image { url label } } } }",
  "variables": {
    "sku": "TEST-SKU-001"
  }
}

###

### Magento 2 GraphQL: Customer Login Mutation
POST {{magento_base_url}}/graphql
Content-Type: application/json

{
  "query": "mutation GenerateCustomerToken($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token } }",
  "variables": {
    "email": "test@example.com",
    "password": "{{customer_password}}"
  }
}

6. Magento 2 GraphQL API in PhpStorm

The Magento 2 GraphQL API defines its schema in .graphqls files inside each module, under etc/schema.graphqls. PhpStorm recognizes these files automatically once the GraphQL plugin is configured. This makes the entire Magento schema available for autocompletion, including fields added by installed third-party modules.

For developing your own GraphQL resolvers in Magento, this means: when you write a schema.graphqls for a custom module, PhpStorm immediately validates whether the referenced types exist in the schema, whether the resolver classes carry the correct interface name, and whether the field types are consistent. This eliminates the common error source where a schema is defined that doesn't match the actual resolver return type.

7. Fragments and shared query libraries

GraphQL fragments allow field selections to be reused across multiple queries. In larger projects, dozens of queries with identical structures quickly emerge, for example the same ProductFragment with fields for image, price and SKU every time. PhpStorm recognizes fragment definitions and completes fragment references (...FragmentName) with a list of available, type-compatible fragments.

For team projects, a dedicated directory structure for GraphQL files is worthwhile: src/graphql/queries/, src/graphql/mutations/, src/graphql/fragments/. PhpStorm shows the definition on Ctrl+Click on a fragment name, no matter which file it lives in. "Find Usages" (Alt+F7) shows every place where a fragment is used, which makes refactoring considerably safer.


# src/graphql/fragments/ProductPrice.graphql
# Shared fragment (PhpStorm tracks all usages with Alt+F7)

fragment ProductPrice on ProductInterface {
  price_range {
    minimum_price {
      regular_price {
        value
        currency
      }
      final_price {
        value
        currency
      }
      discount {
        amount_off
        percent_off
      }
    }
  }
}

# src/graphql/queries/ProductListing.graphql
# PhpStorm autocompletes fragment name, validates type compatibility

query GetProductListing($categoryId: String!, $pageSize: Int = 12) {
  products(
    filter: { category_id: { eq: $categoryId } }
    pageSize: $pageSize
  ) {
    total_count
    items {
      id
      name
      sku
      url_key
      ...ProductPrice
      small_image {
        url
        label
      }
    }
  }
}

8. Custom GraphQL types for Magento modules

When a custom Magento module extends the GraphQL API, the work starts with the schema.graphqls file. PhpStorm validates this file against the base schema and immediately flags when a type is extended (type Query @resolver) that doesn't exist in the schema, or when a referenced return type isn't defined. This saves a full Magento deploy followed by a schema validation error.

The resolver class referenced via the @resolver directive in schema.graphqls must implement the ResolverInterface from Magento\Framework\GraphQl\Query\ResolverInterface. PhpStorm jumps directly to the PHP class with Ctrl+Click on the class name in the GraphQL file, provided the configuration is correct. This navigation makes the development cycle between schema definition and resolver implementation considerably faster.

9. Tooling comparison: PhpStorm vs. standalone clients

For day-to-day GraphQL development in a PHP project, PhpStorm's integration offers clear advantages over external tools like GraphiQL, Altair or Postman, but also specific limitations that justify using external tools in some scenarios.

Feature PhpStorm GraphiQL / Altair Postman
Schema autocompletion Full, offline Online introspection Limited
Query versioning .http and .graphql in Git Not native Collections exportable
Inline PHP navigation Ctrl+Click to resolver classes Not available Not available
Interactive exploration Possible, but less visual Optimal for exploration Good
Team sharing Files in the repository Manual Workspace sync

The most sensible combination in practice: PhpStorm for day-to-day development with schema autocompletion, inline validation and versioned HTTP requests. GraphiQL or Altair for the initial exploration of an unfamiliar schema, where visual documentation navigation is helpful. Postman for cross-team sharing of API tests with non-developers.

Mironsoft

Magento 2, GraphQL API development and PHP consulting

Building GraphQL APIs for your Magento project?

We develop GraphQL resolvers, schema extensions and API integrations for Magento 2, with full PhpStorm integration, type safety and automated tests.

Schema design

Type-safe GraphQL schemas for Magento modules with complete documentation and validation

Resolver development

PHP resolver classes with performance optimization, caching and error handling per Magento standards

API integration

Integrating headless frontends, PWA connections and third-party GraphQL APIs into Magento

10. Summary

The GraphQL tooling in PhpStorm transforms API development from a trial-and-error process into a type-safe, validation-driven workflow. Schema autocompletion, inline error display and introspection straight from the running Magento server make the complex Magento GraphQL schema manageable. The built-in HTTP client with versioned .http files replaces external tools for everyday testing needs.

For teams developing Magento modules with their own GraphQL extensions, the IDE integration brings a concrete quality benefit: schema errors are caught before the deploy, not after. Navigation from the schema directive to the resolver class makes the development cycle faster and less error-prone. Fragment libraries, versioned in the repository and managed by PhpStorm with Find Usages, make refactoring safe.

GraphQL Tooling in PhpStorm, the Essentials at a Glance

Schema setup

graphql.config.yml in the project root with schema URL for introspection. PhpStorm caches the schema locally, so autocompletion works offline too.

HTTP client

.http files for GraphQL queries and mutations, versioned in the repository, environment variables from http-client.env.json, result shown directly in the editor.

Magento integration

schema.graphqls files in modules are recognized automatically. Ctrl+Click on the @resolver class name jumps directly to the PHP resolver class.

Fragment libraries

Fragment definitions in separate .graphql files. Alt+F7 shows all usages. Ctrl+Click navigates to the definition. Type compatibility is validated.

11. FAQ: GraphQL Tooling in PhpStorm

1Is the GraphQL plugin free?
Integrated by default in PhpStorm 2023.x and newer. Installable for free via the plugin marketplace in older versions.
2How do I load the Magento schema into PhpStorm?
Create a graphql.config.yml with an introspection URL. PhpStorm loads via introspection and caches locally, so autocompletion is then available offline too.
3Are queries possible without a running server?
Yes, PhpStorm caches the schema locally after the first introspection. Completion and validation run offline. Only running a query needs the server.
4How does the HTTP client for GraphQL work?
.http file with a POST request, content type application/json, GraphQL query as JSON body. Ctrl+Enter runs it, and the result appears formatted directly in the editor.
5Navigation from schema.graphqls to the PHP class?
Ctrl+Click on the class name in @resolver(class="...") jumps directly to the PHP resolver class, provided autoloading is configured correctly.
6How do I share queries with the team?
Version .http and .graphql files in the repository. Everyone has the same queries. Store secrets in http-client.private.env.json (not versioned).
7Are fragment references validated?
Yes, PhpStorm checks whether a fragment is defined and whether the type is compatible. Missing definitions are flagged as errors. Alt+F7 shows all usages.
8Are custom Magento schemas recognized?
Yes, add a glob pattern for all schema.graphqls files in graphql.config.yml. PhpStorm combines all found schema files into the overall schema.
9How do I authenticate requests?
Bearer token in the .http file as a header. Secrets in http-client.private.env.json (not versioned), PhpStorm substitutes them as variables automatically.
10Also suitable for non-Magento APIs?
Completely, GitHub, Shopify, Contentful and all GraphQL APIs with introspection support work. Multiple endpoints can be configured in graphql.config.yml.