In Laravel 6, since the field name of the interface responds in the form of hump, and the name of the table field is underlined in the form of lowercase letters, the processing of mutual conversion
1. The name of the table field is in the form of lowercase letters and underscores. as shown in Figure 1
2. The interface is implemented based on GraphQL, and the field name that is specified as the interface response must be in the form of hump.
type ThemeAsset
{
"ID"
id: ID!
"主题ID"
themeId: String!,
"版本"
version: String!,
"内容"
content: String,
"路径,相对于主题的路径,如 ages/index.blade.php"
key: String!,
"MIME 类型"
mimeType: String!,
"类别,page、component、config(仅这3种类型有配置),asset、unknown"
category: String!,
"主题的 Schema,包括页面、主题、组件"
schema: String,
"创建时间"
createdAt: DateTime!
"更新时间"
updatedAt: DateTime
}
3. Print the parser /modules/themestore/resolver/onlinestoreetheme/themeassesResolver.php method $themeAssets, the object property name is underlined in lowercase letters. as shown in Figure 2
get();
print_r($themeAssets);
exit;
}
}
4. Scenario 1 is to traverse $themeasses and reassign to a new array, and set the key name in the form of hump in this array. Scenario 2 is the name of the hump form renamed in the select query statement. The final decision was adopted.
public function __invoke($rootValue, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
{
$themeId = $rootValue['themeAssets']['theme_id'];
$themeAssets = ThemeAsset::where('theme_id', $themeId)
->select(
'id',
'theme_id as themeId',
'version',
'content',
'asset_key as key',
'mime_type as mimeType',
'category',
'schema',
'created_at as createdAt',
'updated_at as updatedAt'
)
->get();
return $themeAssets;
}
5. The request interface, the response field name is the hump form. in line with expectations. as shown in Figure 3
6. Check the generated native SQL statement in the log. as shown in Figure 4
select
`id`,
`theme_id` as `themeId`,
`version`,
`content`,
`asset_key` as `key`,
`mime_type` as `mimeType`,
`category`,
`schema`,
`created_at` as `createdAt`,
`updated_at` as `updated_at`
from
`theme_asset`
where
`theme_id` = 'vogue'



