Needs work
Project:
Migrate Plus
Version:
8.x-4.x-dev
Component:
Plugins
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Feb 2019 at 08:29 UTC
Updated:
7 May 2020 at 16:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
robin.ingelbrecht commentedComment #3
robin.ingelbrecht commentedComment #4
weynhamzI am working on the exact same thing now, also created a plugin that supports the relationships and included, will share soon.
Comment #5
robin.ingelbrecht commentedVersion with cached responses:
Comment #6
weynhamzMaybe we can somehow join forces together, here is my version.
Currently implemented:
1. introduced a 'relationship' configuration key to specify the 'field key' in relationships
2. automatically add the required relationship as include to API request
3. 'selector' configures the selector path for the included object
4. support paging 'next'
An example:
JSON:API response
Configuration example
Comment #7
heddnThe other issue #2640516: Support paging through multiple requests already has some level of tests and has been open for a while. Let's consolidate our work on it.
Comment #8
weynhamz@heddn, this is not just about the paging for jsonapi support, it also includes the support for jsonapi specific relationships/include handling, after the #2640516 commited, we can adapt this to the built-in paging support.
Comment #9
heddnExpound on the concept of relationships? What is it all about? I'm not familiar with it.
Comment #10
weynhamz@heddn, JSON:API handles entity_references as relationships, as you can see from my previous screenshot, there is a 'relationships' key in the response, it gives the UUID for the referenced entity. JSON:API also support by adding an 'include' query parameter to the API to include the needed 'relationship' into the response as 'included' key.
https://www.drupal.org/docs/8/modules/jsonapi/includes
My approach above added below configuration change to the fields definition of extended json parser, it says for parent field, extract from /attributes/tid within the parent relationship of the included section. The parser tries to find all defined/needed relationship in the configuration and automatically added them to the API request as include query parameter.
And the work here is still in progress, I have actually created a JSON:API fetcher today as well, added support for filtering, see https://www.drupal.org/docs/8/modules/jsonapi/filtering.
Basically, it tries to turn configuration like below
to a valid JSON:API filter query parameter like this.
I will submit my patch later.
In long term, I want help make migrate_plus have full JSON:API source support.
Comment #11
benjifisher+1 for the idea of a data parser, or perhaps a source plugin, for JSON:API. Let's make it easy to import data that uses this standard.
This may be the future of migration: old system produces JSON:API and then the Migrate API sucks it into Drupal.
Now that Drupal core includes the JSON:API module, this could become the standard method for migrations from D8 to D8, or D8 to D9. It is not a new idea: see https://www.lullabot.com/articles/pull-content-from-a-remote-drupal-8-si...
Comment #12
ttamniwdoog commentedLooks like https://www.drupal.org/project/jsonapi_include took care of the relationships selector until recently https://www.drupal.org/project/jsonapi_include/issues/3057327 . Since jsonapi_include will not work, if I am reading the Normalizer's changes correctly here: https://www.drupal.org/project/jsonapi/issues/2923779#comment-12407443 , is there a way to "get" the referenced entity information without a separate "GET" request?
Comment #13
weynhamz@benjifisher, I already have a working data_parser and data_fether for url source plugin, I was also thinking to create a jsonapi source plugin as well, I will try to consolidate the work I have done, and submit a patch for review by this weekend.
@ttamniwdoog, I think it is already within the jsonapi module in core, with 'include' parameter, it will contain the referenced entity within the same request.
Comment #14
weynhamzJust in case someone is interested, here are the data_parser and data_fetcher plugin created and in use in of one my projects.
Comment #15
ttamniwdoog commentedThanks @weynhamz. I think you are right but since I have more than one entity reference on this content type, when I use the include parameter in the URL, like this: https://[domain].tld/jsonapi/node/blog_post?include=field_tags.vid&include=field_category.vid I only see the last name/value pair named in the result set. I may need to write a source plugin for my use case but would like to know if I am mistaken before I take that road. Thanks again
Comment #16
weynhamz@ttamniwdoog I think it should be like this https://[domain].tld/jsonapi/node/blog_post?include=field_tags,field_category
Comment #17
ttamniwdoog commentedThanks @weynhamz. That works great. In your .yml file, which source item_selector are you able to use to get both "data" and "included" since they both are at the root level of our JSON?
Comment #18
zipme_hkt commentedi was update new release help to merge include and relationship: https://www.drupal.org/project/jsonapi_include.
Now you can also toggle include data with query param jsonapi_include=1 or jsonapi_include=0
It help to easy work with migrate module.
Comment #19
dmlb2000 commentedYet another project in this space...
https://git.drupalcode.org/project/migrate_source_jsonapi
Has some similar code as above.