Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-micro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-micro
Commits
2bad7f8a
Commit
2bad7f8a
authored
Jan 13, 2021
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shopify添加graphQL接口支持
parent
49c5f416
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
1 deletion
+90
-1
ShopifyApp.php
src/Shopify/ShopifyApp.php
+4
-0
AbstractShopify.php
src/Shopify/lib/AbstractShopify.php
+1
-1
Graphql.php
src/Shopify/lib/Graphql.php
+47
-0
HttpRequestGraphQL.php
src/Shopify/tools/HttpRequestGraphQL.php
+38
-0
No files found.
src/Shopify/ShopifyApp.php
View file @
2bad7f8a
...
@@ -15,6 +15,7 @@ use Meibuyu\Micro\Shopify\lib\Collection;
...
@@ -15,6 +15,7 @@ use Meibuyu\Micro\Shopify\lib\Collection;
use
Meibuyu\Micro\Shopify\lib\CustomCollection
;
use
Meibuyu\Micro\Shopify\lib\CustomCollection
;
use
Meibuyu\Micro\Shopify\lib\Event
;
use
Meibuyu\Micro\Shopify\lib\Event
;
use
Meibuyu\Micro\Shopify\lib\FulfillmentService
;
use
Meibuyu\Micro\Shopify\lib\FulfillmentService
;
use
Meibuyu\Micro\Shopify\lib\Graphql
;
use
Meibuyu\Micro\Shopify\lib\InventoryItem
;
use
Meibuyu\Micro\Shopify\lib\InventoryItem
;
use
Meibuyu\Micro\Shopify\lib\InventoryLevel
;
use
Meibuyu\Micro\Shopify\lib\InventoryLevel
;
use
Meibuyu\Micro\Shopify\lib\Location
;
use
Meibuyu\Micro\Shopify\lib\Location
;
...
@@ -43,6 +44,7 @@ use Meibuyu\Micro\Shopify\lib\Webhook;
...
@@ -43,6 +44,7 @@ use Meibuyu\Micro\Shopify\lib\Webhook;
* @property-read Order $Order
* @property-read Order $Order
* @property-read Event $Event
* @property-read Event $Event
* @property-read FulfillmentService $FulfillmentService
* @property-read FulfillmentService $FulfillmentService
* @property-read GraphQL $GraphQL
*
*
* @method Webhook Webhook(integer $id = null)
* @method Webhook Webhook(integer $id = null)
* @method Collection Collection(integer $id = null)
* @method Collection Collection(integer $id = null)
...
@@ -57,6 +59,7 @@ use Meibuyu\Micro\Shopify\lib\Webhook;
...
@@ -57,6 +59,7 @@ use Meibuyu\Micro\Shopify\lib\Webhook;
* @method Order Order(integer $id = null)
* @method Order Order(integer $id = null)
* @method Event Event(integer $id = null)
* @method Event Event(integer $id = null)
* @method FulfillmentService FulfillmentService(integer $id = null)
* @method FulfillmentService FulfillmentService(integer $id = null)
* @method GraphQL GraphQL()
*
*
*/
*/
class
ShopifyApp
class
ShopifyApp
...
@@ -77,6 +80,7 @@ class ShopifyApp
...
@@ -77,6 +80,7 @@ class ShopifyApp
'Order'
,
'Order'
,
'Event'
,
'Event'
,
'FulfillmentService'
,
'FulfillmentService'
,
'GraphQL'
,
];
];
protected
$childResources
=
array
(
protected
$childResources
=
array
(
...
...
src/Shopify/lib/AbstractShopify.php
View file @
2bad7f8a
...
@@ -55,7 +55,7 @@ abstract class AbstractShopify
...
@@ -55,7 +55,7 @@ abstract class AbstractShopify
{
{
$this
->
config
=
$config
;
$this
->
config
=
$config
;
$this
->
id
=
$id
;
$this
->
id
=
$id
;
$this
->
pluralizeKey
=
$this
->
resourceKey
.
's'
;
$this
->
pluralizeKey
=
$this
->
pluralizeKey
?:
$this
->
resourceKey
.
's'
;
$this
->
resourceUrl
=
(
$parentResourceUrl
?
"
$parentResourceUrl
/"
:
$config
[
'api_url'
])
.
$this
->
pluralizeKey
.
(
$this
->
id
?
"/
{
$this
->
id
}
"
:
''
);
$this
->
resourceUrl
=
(
$parentResourceUrl
?
"
$parentResourceUrl
/"
:
$config
[
'api_url'
])
.
$this
->
pluralizeKey
.
(
$this
->
id
?
"/
{
$this
->
id
}
"
:
''
);
if
(
isset
(
$config
[
'api_password'
]))
{
if
(
isset
(
$config
[
'api_password'
]))
{
...
...
src/Shopify/lib/Graphql.php
0 → 100644
View file @
2bad7f8a
<?php
/**
* Created by PhpStorm.
* User: Zero
* Date: 2021/01/08
* Time: 09:34:30
*/
namespace
Meibuyu\Micro\Shopify\lib
;
use
Exception
;
use
Meibuyu\Micro\Shopify\tools\HttpRequestGraphQL
;
/**
* Class Graphql
* @package Meibuyu\Micro\Shopify\lib
*/
class
Graphql
extends
AbstractShopify
{
protected
$resourceKey
=
'graphql'
;
protected
$pluralizeKey
=
'graphql'
;
public
function
post
(
$graphQL
,
$url
=
null
,
$wrapData
=
false
,
$variables
=
null
)
{
if
(
!
$url
)
$url
=
$this
->
generateUrl
();
$response
=
HttpRequestGraphQL
::
post
(
$url
,
$graphQL
,
$this
->
httpHeaders
,
$variables
);
return
$this
->
processResponse
(
$response
);
}
public
function
get
(
$urlParams
=
array
(),
$url
=
null
,
$dataKey
=
null
)
{
throw
new
Exception
(
"GraphQL 只支持 POST 请求!"
);
}
public
function
put
(
$id
,
$dataArray
,
$url
=
null
,
$wrapData
=
true
)
{
throw
new
Exception
(
"GraphQL 只支持 POST 请求!"
);
}
public
function
delete
(
$id
=
null
,
$urlParams
=
[],
$url
=
null
)
{
throw
new
Exception
(
"GraphQL 只支持 POST 请求!"
);
}
}
src/Shopify/tools/HttpRequestGraphQL.php
0 → 100644
View file @
2bad7f8a
<?php
/**
* Created by PhpStorm.
* User: Zero
* Time: 2021/1/11 10:10
*/
namespace
Meibuyu\Micro\Shopify\tools
;
use
Meibuyu\Micro\Tools\CurlRequest
;
use
Meibuyu\Micro\Tools\HttpRequestJson
;
class
HttpRequestGraphQL
extends
HttpRequestJson
{
protected
static
function
prepareRequest
(
$headers
=
[],
$data
=
[],
$variables
=
null
)
{
if
(
is_string
(
$data
))
{
$postDataGraphQL
=
$data
;
}
else
{
throw
new
\Exception
(
"Only GraphQL string is allowed!"
);
}
if
(
is_array
(
$variables
))
{
$postDataGraphQL
=
json_encode
([
'query'
=>
$data
,
'variables'
=>
$variables
]);
$headers
[
'Content-type'
]
=
'application/json'
;
}
else
{
$headers
[
'Content-type'
]
=
'application/graphql'
;
}
return
[
$headers
,
$postDataGraphQL
];
}
public
static
function
post
(
$url
,
$data
,
$headers
=
[],
$variables
=
null
)
{
[
$headers
,
$postDataGraphQL
]
=
self
::
prepareRequest
(
$headers
,
$data
,
$variables
);
return
CurlRequest
::
post
(
$url
,
$postDataGraphQL
,
$headers
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment