String arguments are not possible

Created on 14 February 2023, over 1 year ago
Updated 16 February 2023, over 1 year ago

Problem/Motivation

When i try to use string arguments, i get the error:

Could not retrieve source count from article: Expected type String, found Morty.

Steps to reproduce

Use this migration:

id: article
label: Articles
migration_tags: null
data_key: results
source:
  plugin: graphql
  endpoint: https://rickandmortyapi.com/graphql
  query:
    characters:
      arguments:
        filter:
          name: "Morty"
      fields:
        - results:
            - id
            - name
  ids:
    id:
      type: string
process:
  title: name

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

and run drush migrate:status

You can go here: https://studio.apollographql.com/public/rick-and-morty-a3b90u/explorer?v... and run the same query and get results:

query Query {
  characters(filter: {name: "Morty"}) {
    results {
      id
      name
    }
  }
}

Proposed resolution

Not sure, but it looks like it has to do with /src/GraphQL/Client.php:72:

$argumentsToString = preg_replace("/['\"]/", '', $argumentsToString);

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States bander2

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bander2
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Thank you @bander2 for the preliminary analysis you provided me.
    I will try to understand it better and propose a solution as soon as possible.

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @bander2, i ran a quick check and fortunately there's no bug.
    The problem lies in your configuration. The data_key property shold be specified under `source:` and not before. You can also see this from the documentation on the module's home page.
    As you can see by using the following migration:

    id: migrate_morty
    label: Migrate Morty to Articles
    migration_tags: null
    source:
      plugin: graphql
      endpoint: https://rickandmortyapi.com/graphql
      data_key: results
      query:
        characters:
          arguments:
            filter:
              name: "Morty"
          fields:
            - results:
                - id
                - name
      ids:
        id:
          type: string
    process:
      title: name
    
    destination:
      plugin: 'entity:node'
      default_bundle: article
    

    I got the desired result:

    I close the issue, thank you.

  • Status changed to Closed: works as designed over 1 year ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹
  • 🇺🇸United States bander2

    I am still getting this with your migration on a fresh install:

    Drupal: 9.5.3
    PHP: 8.0.27
    Drush: 9.0.27
    Migrate Source GraphQL: 2.03

    Running drush mim migrate_morty -v gives me:

    In Results.php line 54:          
    [GraphQL\Exception\QueryError]
    Expected type String, found Morty. 
    

    drush migrate:status -v produces this output.

     [error]  Could not retrieve source count from migrate_morty: Expected type String, found Morty. 
     [error]  Could not retrieve source count from migrate_morty: Expected type String, found Morty. 
     [error]  Could not retrieve source count from migrate_morty: Expected type String, found Morty. 
     --------------- -------- ------- ---------- ------------- --------------- 
      Migration ID    Status   Total   Imported   Unprocessed   Last Imported  
     --------------- -------- ------- ---------- ------------- --------------- 
      migrate_morty   Idle     N/A     0          N/A                          
     --------------- -------- ------- ---------- ------------- --------------- 
    

    The error itself comes from the endpoint. I believe that we are intending to send a query like this:

    query Query {
      characters(filter: {name: "Morty"}) {
        results {
          id
          name
        }
      }
    }
    

    But instead are sending:

    query Query {
      characters(filter: {name: Morty}) {
        results {
          id
          name
        }
      }
    }
    

    I don't know what the difference could be between your environment and mine that would account for this.

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @bander2, i will check again and let you know soon.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @bander2, i've switched on your same fresh install, and yes. I've the same your error.
    I'm working on a patch.
    Which I will release as soon as possible.
    Thank you.

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @bander2, i've made a patch 3341694_string_arguments_not_possible.patch 3341694_string_arguments_not_possible.patch
    The patch includes:
    - Fix for string arguments
    - Multiple arguments now are supported
    - Errors are now shown directly as drush output without -vvv needs.

    I will include this patch for the 2.0.4 version on which i'm currently working.
    Thank's, let me know how is it.

    • reinchek authored eb027687 on 2.0
      Issue #3341694 by reinchek: String arguments are not possible
      
  • Status changed to Needs review over 1 year ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹
  • Status changed to Fixed over 1 year ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @bander2,
    I have performed further tests and can confirm that it is now working correctly.
    I have released everything in the new version 2.0.4.
    Thank you.

  • Status changed to Fixed over 1 year ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹
  • 🇺🇸United States bander2

    It's working, thanks!

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Thanks to you! 💪

Production build 0.71.5 2024