In Laravel 6 and Lighthouse 5, the parameter $args of the method __invoke has an internal order that is inconsistent with the front-end request parameters
1. The front-end request parameters are shown below. as shown in Figure 1
{
"query": "\nmutation ThemeUpdate($themeId: ID!, $settings: [ThemeSettingDataInput!], $sections: [ThemeSettingsDataSectionInput!], $appEmbeds: [ThemeSettingsDataBlockInput!], $sessionId: String!) {\n onlineStoreThemeSettingsDataUpdate(\n themeId: $themeId\n settings: $settings\n sections: $sections\n appEmbeds: $appEmbeds\n sessionId: $sessionId\n ) {\n sessionId\n __typename\n }\n}\n",
"variables": {
"themeId": "97cdd852-2ca0-48eb-b119-6afb68e2254c",
"settings": [],
"sections": [
{
"sectionId": "announcement-bar",
"disabled": false,
"type": "announcement-bar",
"settings": [
{
"settingId": "enable",
"value": "true"
},
{
"settingId": "homepage_only",
"value": "false"
},
{
"settingId": "sticky",
"value": "false"
}
],
"blocks": [
{
"blockId": "announcement-bar-0",
"disabled": true,
"type": "announcement",
"settings": [
{
"settingId": "text",
"value": "❤Free Shipping Over $100.0❤"
},
{
"settingId": "image",
"value": ""
},
{
"settingId": "mobile_image",
"value": ""
},
{
"settingId": "background_color",
"value": "#000000"
},
{
"settingId": "text_color",
"value": "#ffffff"
},
{
"settingId": "link",
"value": ""
}
]
}
]
},
{
"sectionId": "header",
"disabled": false,
"type": "header",
"settings": [
{
"settingId": "sticky",
"value": "false"
},
{
"settingId": "menu",
"value": ""
},
{
"settingId": "secondary_menu",
"value": ""
},
{
"settingId": "text_color",
"value": "#000000"
},
{
"settingId": "background_color",
"value": "#ffffff"
},
{
"settingId": "transparent",
"value": "true"
},
{
"settingId": "transparent_text_color",
"value": "#ffffff"
},
{
"settingId": "logo",
"value": ""
},
{
"settingId": "logo_max_width",
"value": "180"
}
],
"blocks": []
},
{
"sectionId": "footer",
"disabled": false,
"type": "footer",
"settings": [
{
"settingId": "style",
"value": "first"
},
{
"settingId": "1",
"value": ""
},
{
"settingId": "text_color",
"value": "#222222"
},
{
"settingId": "background_color",
"value": "#f7f7f9"
},
{
"settingId": "4",
"value": ""
},
{
"settingId": "show_payment_icons",
"value": "false"
},
{
"settingId": "show_dmca",
"value": "true"
}
],
"blocks": []
}
],
"appEmbeds": [],
"sessionId": "gY32VAiyjotH8tsfJQZ5aopd9okgAZE4dExf"
},
"operationName": "ThemeUpdate"
}
2. The backend converts the parameter $args of the method __invoke to json, which corresponds to the field in the front-end request body: variables. The code is implemented as follows
public function __invoke($rootValue, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
{
$variables = json_encode($args);
echo $variables;
exit;
}
3. Print the JSON as follows. There are more fields: directive, and then the order of the keys inside the json is inconsistent with the frontend. Appembeds should have been in 4th position, now in 2nd digit
{
"themeId": "97cdd852-2ca0-48eb-b119-6afb68e2254c",
"appEmbeds": [],
"settings": [],
"sections": [
{
"sectionId": "announcement-bar",
"type": "announcement-bar",
"disabled": false,
"settings": [
{
"settingId": "enable",
"value": "true"
},
{
"settingId": "homepage_only",
"value": "false"
},
{
"settingId": "sticky",
"value": "false"
}
],
"blocks": [
{
"blockId": "announcement-bar-0",
"type": "announcement",
"disabled": true,
"settings": [
{
"settingId": "text",
"value": "❤Free Shipping Over $100.0❤"
},
{
"settingId": "image",
"value": ""
},
{
"settingId": "mobile_image",
"value": ""
},
{
"settingId": "background_color",
"value": "#000000"
},
{
"settingId": "text_color",
"value": "#ffffff"
},
{
"settingId": "link",
"value": ""
}
]
}
]
},
{
"sectionId": "header",
"type": "header",
"disabled": false,
"settings": [
{
"settingId": "sticky",
"value": "false"
},
{
"settingId": "menu",
"value": ""
},
{
"settingId": "secondary_menu",
"value": ""
},
{
"settingId": "text_color",
"value": "#000000"
},
{
"settingId": "background_color",
"value": "#ffffff"
},
{
"settingId": "transparent",
"value": "true"
},
{
"settingId": "transparent_text_color",
"value": "#ffffff"
},
{
"settingId": "logo",
"value": ""
},
{
"settingId": "logo_max_width",
"value": "180"
}
],
"blocks": []
},
{
"sectionId": "footer",
"type": "footer",
"disabled": false,
"settings": [
{
"settingId": "style",
"value": "first"
},
{
"settingId": "1",
"value": ""
},
{
"settingId": "text_color",
"value": "#222222"
},
{
"settingId": "background_color",
"value": "#f7f7f9"
},
{
"settingId": "4",
"value": ""
},
{
"settingId": "show_payment_icons",
"value": "false"
},
{
"settingId": "show_dmca",
"value": "true"
}
],
"blocks": []
}
],
"sessionId": "gY32VAiyjotH8tsfJQZ5aopd9okgAZE4dExf",
"directive": null
}
4. Get the request parameters based on ILUMINATE\HTTP\request. The order is still inconsistent. Appembeds should have been in 4th position and now at 2nd.
print_r($context->request()->input('variables'));
exit;
{
"themeId": "97cdd852-2ca0-48eb-b119-6afb68e2254c",
"settings": [],
"sections": [
{
"sectionId": "announcement-bar",
"disabled": false,
"type": "announcement-bar",
"settings": [
{
"settingId": "enable",
"value": "true"
},
{
"settingId": "homepage_only",
"value": "false"
},
{
"settingId": "sticky",
"value": "false"
}
],
"blocks": [
{
"blockId": "announcement-bar-0",
"disabled": false,
"type": "announcement",
"settings": [
{
"settingId": "text",
"value": "❤Free Shipping Over $100.0❤"
},
{
"settingId": "image",
"value": null
},
{
"settingId": "mobile_image",
"value": null
},
{
"settingId": "background_color",
"value": "#000000"
},
{
"settingId": "text_color",
"value": "#ffffff"
},
{
"settingId": "link",
"value": null
}
]
}
]
},
{
"sectionId": "header",
"disabled": false,
"type": "header",
"settings": [
{
"settingId": "sticky",
"value": "false"
},
{
"settingId": "menu",
"value": null
},
{
"settingId": "secondary_menu",
"value": null
},
{
"settingId": "text_color",
"value": "#000000"
},
{
"settingId": "background_color",
"value": "#ffffff"
},
{
"settingId": "transparent",
"value": "true"
},
{
"settingId": "transparent_text_color",
"value": "#ffffff"
},
{
"settingId": "logo",
"value": null
},
{
"settingId": "logo_max_width",
"value": "180"
}
],
"blocks": []
},
{
"sectionId": "footer",
"disabled": false,
"type": "footer",
"settings": [
{
"settingId": "style",
"value": "first"
},
{
"settingId": "1",
"value": null
},
{
"settingId": "text_color",
"value": "#222222"
},
{
"settingId": "background_color",
"value": "#f7f7f9"
},
{
"settingId": "4",
"value": null
},
{
"settingId": "show_payment_icons",
"value": "false"
},
{
"settingId": "show_dmca",
"value": "true"
}
],
"blocks": []
}
],
"appEmbeds": [],
"sessionId": "gY32VAiyjotH8tsfJQZ5aopd9okgAZE4dExf"
}
5. Obtain the original content of the request body based on illuminate\http\request. The order of the front and back ends is the same. The location of Appembeds is now 4th. The code is implemented as follows
$content = json_decode($context->request()->getContent(), true);
echo json_encode($content['variables']);
exit;
{
"themeId": "97cdd852-2ca0-48eb-b119-6afb68e2254c",
"settings": [],
"sections": [
{
"sectionId": "announcement-bar",
"disabled": false,
"type": "announcement-bar",
"settings": [
{
"settingId": "enable",
"value": "true"
},
{
"settingId": "homepage_only",
"value": "false"
},
{
"settingId": "sticky",
"value": "false"
}
],
"blocks": [
{
"blockId": "announcement-bar-0",
"disabled": false,
"type": "announcement",
"settings": [
{
"settingId": "text",
"value": "❤Free Shipping Over $100.0❤"
},
{
"settingId": "image",
"value": ""
},
{
"settingId": "mobile_image",
"value": ""
},
{
"settingId": "background_color",
"value": "#000000"
},
{
"settingId": "text_color",
"value": "#ffffff"
},
{
"settingId": "link",
"value": ""
}
]
}
]
},
{
"sectionId": "header",
"disabled": false,
"type": "header",
"settings": [
{
"settingId": "sticky",
"value": "false"
},
{
"settingId": "menu",
"value": ""
},
{
"settingId": "secondary_menu",
"value": ""
},
{
"settingId": "text_color",
"value": "#000000"
},
{
"settingId": "background_color",
"value": "#ffffff"
},
{
"settingId": "transparent",
"value": "true"
},
{
"settingId": "transparent_text_color",
"value": "#ffffff"
},
{
"settingId": "logo",
"value": ""
},
{
"settingId": "logo_max_width",
"value": "180"
}
],
"blocks": []
},
{
"sectionId": "footer",
"disabled": false,
"type": "footer",
"settings": [
{
"settingId": "style",
"value": "first"
},
{
"settingId": "1",
"value": ""
},
{
"settingId": "text_color",
"value": "#222222"
},
{
"settingId": "background_color",
"value": "#f7f7f9"
},
{
"settingId": "4",
"value": ""
},
{
"settingId": "show_payment_icons",
"value": "false"
},
{
"settingId": "show_dmca",
"value": "true"
}
],
"blocks": []
}
],
"appEmbeds": [],
"sessionId": "gY32VAiyjotH8tsfJQZ5aopd9okgAZE4dExf"
}
