Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Migrate Source GraphQL

154 sites Security covered
View on drupal.org

This module allows you to migrate data from a GraphQL endpoint into Drupal. You can configure the GraphQL endpoint, define authentication, and specify the GraphQL query to extract the data you need.

🇵🇸

This module extends the list of core migrations source by adding the new GraphQL query source.
For further details and advanced options visit the complete module documentation.

What's means?

This means that like as Migrate Source CSV, for example, you can create a migration YAML file inside of which configure the GraphQL endpoint and write the query from which to extract the contents.

Features

  • GraphQL Endpoint: Mandatory option to define the endpoint URL.
  • Authentication Options:
    • auth_scheme: Supports various auth schemes (Basic, Bearer, Digest, etc.).
    • auth_parameter: Paired with auth_scheme to generate the Authorization header.
  • Data Key Customization: Define a custom name for the "data" property or use nested structures with property separators or dynamic mappings.
  • Custom IDs: Specify custom fields and types for item IDs (defaults to id as a string if omitted).
  • Query Definition: Mandatory query structure:
    • arguments: Allows filtering, pagination, etc.
    • fields: Defines query response fields, with a mandatory fields property in YAML.
  • Iterator Placeholder: % placeholder allows dynamic mapping within nested arrays.
  • ResultsEvent:
    • getResults(): Retrieves query results.
    • setResults(): Enables result modifications, allowing modules to subscribe and manipulate migration data.

How it works?

Source options

The graphql source offers a number of options to allow you to best configure your query. In short:

source:
  plugin: graphql

  # [mandatory] The GraphQL endpoint
  endpoint: <value>
  # [optional] Basic, Bearer, Digest, etc...
  auth_scheme: <value>
  # [optional] Paired with auth_scheme will generate the string that 
  # will be passed to the Authorization header
  auth_parameter: <value>
  # [optional] Used to specify a different name for "data" property
  data_key: <value>
  # [mandatory] from here starts the query definition
  query:
    # [mandatory] The query name
    <query_name>:
      # [optional] Query arguments (filtering, pagination, and so on...). 
      # See the example below.
      arguments:
      # [mandatory] Query fields definition
      fields:
        # [mandatory] It is 'data' if no different value has been set in data_key
        - <data|data_key>:
            - <field_1>
            - <field_2>
            - <field_n>

Let's take an example.

For this example we will use the GraphQLZero (Fake Online GraphQL API for Testing and Prototyping) from which we will migrate some entities, that on GraphQLZero are called posts, into the our Drupal instance populating the our's default articles.

Follow GraphQL query shows how to get a list of posts from GraphQLZero:

query {
  posts {
    data {
      id
      title
      body
    }
  }
}

The response:

The migration

So we, as first thing, have to setup the YAML migration file. As like as follow:

id: migrate_graphql_posts_articles
label: 'Migrate posts from GraphQLZero'
migration_tags: null
source:
  plugin: graphql

  endpoint: 'https://graphqlzero.almansi.me/api'
  auth_scheme: Bearer
  auth_parameter: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3...'
  query:
    posts:
      fields:
        -
          data:
            - id
            - title
            - body
  ids:
    id:
      type: string
process:
  title: title
  body: body

destination:
  plugin: 'entity:node'
  default_bundle: article

migration_dependencies: {  }

The only difference between the GraphQL query and the YAML transposition is the mandatory property fields, the usefulness of which is solely a matter of choice for the developer.

For further details and advanced options, including configuring the data_key parameter and using different authorization schemas, visit the complete module documentation in the "How it Works?" section.

Activity

Total releases
1
First release
Jun 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
2.1.1 Stable Jun 14, 2025