在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):dadish/ProcessGraphQL开源软件地址(OpenSource Url):https://github.com/dadish/ProcessGraphQL开源编程语言(OpenSource Language):PHP 98.8%开源软件介绍(OpenSource Introduction):ProcessGraphQLGraphQL for ProcessWire. Table of Contents
About ProcessGraphQLProcessGraphQL is a module for ProcessWire. The module seamlessly integrates to your ProcessWire web app and allows you to serve the GraphQL api of your existing content. You don't need to apply changes to your content or it's structure. Just choose what you want to serve via GraphQL and your API is ready. Here is an example of ProcessGraphQL in action after installing it to skyscrapers profile. See more demo here. Requirements
InstallationTo install the module, go to Modules -> Install -> Add New. Scroll down to get to the section Add Module from URL. Paste the URL of the latest release into the Module ZIP file URL field and press Download. ProcessWire will download this module and place it at After you installed the ProcessGraphQL, you will be taken to the module configuration page. Where you will have many options to setup the module the way you want. More on that in the section below. ConfigurationThe ProcessGraphQL module will serve only the parts of your content which you explicitly ask for. The module configuration page provides you with exactly that. Here you should choose what parts of your website should be available via GraphQL API. The options are grouped into four sections. TemplatesIn this section you choose the templates that you want ProcessGraphQL to handle. The pages associated with the templates you choose here will be available to the superuser immediately. You will see later how you can grant access to these template to other user roles as well.
FieldsHere you should choose the fields that you want to be available via GraphQL API. These fields also will immediately be available to the superuser.
Page FieldsThese are the built-in fields of the ProcessWire Page. You should choose only the ones you will certainly need in your API. E.g. PageFile FieldsBuilt-in fields of the FieldtypeFile and FieldtypeImage. E.g. After you chose all parts you need, submit the module configuration. Now you can go to Setup -> GraphQL and you will see the GraphiQL GUI where you can query your GraphQL api. Go ahead and play with it. Access ControlAs mentioned above, the GraphQL API will be accessible only by superuser. To grant access to users with different roles, you need to use Access settings in your templates and fields. Say you want a user with role The above configuration will allow the Select the Basics tab for The ProcessWire's Access Control system is very flexible and allows you to fine tune your access rules the way you want. You will use it to control access to your GraphQL API as well. ProcessGraphQL treats permissions exactly the way ProcessWire does. Below is the list of permissions supported by ProcessGraphQL.
Learn more about ProcessWire's Access Control system here. APIGraphQL endpointIf you wish to expose your GraphQL api, you can do so by calling a single method on ProcessGraphQL module in your template file. Here is what it might look like <?php
// /site/templates/graphql.php
$result = $modules->get('ProcessGraphQL')->executeGraphQL();
echo json_encode($result); This will automatically capture the GraphQL request from your client and respond to it. If you need some manual control on this <?php
// /site/templates/graphql.php
$query = $input->post->query;
$variables = $input->post->variables;
// modify your $query and $variables here...
$result = $modules->get('ProcessGraphQL')->executeGraphQL($query, $variables);
echo json_encode($result); GraphiQL endpointYou can also expose the GraphiQL from within your template. Here is how you can do that. <?php
// /site/templates/graphiql.php
echo $modules->get('ProcessGraphQL')->executeGraphiQL();
By default the GraphiQL is pointed to your admin GraphQL server, which is <?php
// /site/templates/graphiql.php
$ProcessGraphQL = $modules->get('ProcessGraphQL');
$ProcessGraphQL->GraphQLServerUrl = '/graphql/';
echo $ProcessGraphQL->executeGraphiQL();
Modifying Query and MutationThere could be cases when you want to include some custom fields into your GraphQL query and mutation operation. There are two ProcessWire hooks that allows you to do that. getQueryFields() hookYou can hook into <?php namespace ProcessWire;
use GraphQL\Type\Definition\Type;
$processGraphQL = $modules->get('ProcessGraphQL');
wire()->addHookAfter("ProcessGraphQL::getQueryFields", function (
$event
) {
$fields = $event->return;
$fields[] = [
"name" => "hello",
"type" => Type::string(),
"resolve" => function () {
return "world!";
},
];
$event->return = $fields;
});
echo $processGraphQL->executeGraphQL(); The above code will add a getMutation() hookYou can also hook into FeaturesGraphQL OperationsThe module will eventually support all operations you need to build fully functioning SPA. For now you can perform most common operations.
Compatible FieldsAt this moment ProcessGraphQL handles most of the ProcessWire's core fieldtypes. Those are:
Third-party Fieldtypes SupportYou can add support for any third-party fieldtype by creating a module for it. The example module that you can refer to is GraphQLFieldtypeMapMarker that adds support for FieldtypeMapMarker fieldtype. Below are the basic requirements that this kind of modules should fulfill. Naming of the ModuleName your module exactly as the Fieldtype module you are adding support for with Required methodsThere are three required methods. public static function getType(Field $field)The value type that the fieldtype returns. Could be string, number, boolean or an abject with bunch of subfields. public static function getInputType(Field $field)The value type that the fieldtype accepts. Could be different value type than it returns. For instance FieldtypePage returns a Page object with lots of subfields, but can accept a simple integer (id of the page) as a value. public static function setValue(Page $page, Field $field, $value)Given the
When your module is ready, just install it and it should be automatically used by ProcessGraphQL and your fieldtype should be available via your GraphQL api. TroubleshootingSyntax Error: Unexpected <EOF>If you are getting an error response from your GraphQL API with the following structure {
"errors": [
{
"message": "Syntax Error: Unexpected <EOF>",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 1
}
]
}
]
} then it is probably because ProcessGraphQL is not receiving your query. The reason for this could be that the url you're making a request to does not end with License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论