{"id":20506073,"url":"https://github.com/robinradic/graphql-streams-api","last_synced_at":"2025-04-13T21:14:07.230Z","repository":{"id":62532523,"uuid":"152540616","full_name":"RobinRadic/graphql-streams-api","owner":"RobinRadic","description":"A PyroCMS Module that provides an easy yet flexible way to bind your PyroCMS Streams to a GraphQL API.","archived":false,"fork":false,"pushed_at":"2018-10-20T15:45:55.000Z","size":332,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T21:14:07.051Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobinRadic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-11T06:17:55.000Z","updated_at":"2022-03-16T14:06:11.000Z","dependencies_parsed_at":"2022-11-02T16:01:00.700Z","dependency_job_id":null,"html_url":"https://github.com/RobinRadic/graphql-streams-api","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinRadic%2Fgraphql-streams-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinRadic%2Fgraphql-streams-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinRadic%2Fgraphql-streams-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinRadic%2Fgraphql-streams-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobinRadic","download_url":"https://codeload.github.com/RobinRadic/graphql-streams-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782260,"owners_count":21160717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T19:54:04.328Z","updated_at":"2025-04-13T21:14:07.210Z","avatar_url":"https://github.com/RobinRadic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyroCMS GraphQL Streams Api Module\n\n- [Introduction](#introduction)\n- [Preview](#preview)\n- [Documentation](#documentation)\n    - [Installation](#installation)\n    - [Customization](#customization)\n    - [Generate](#generate)\n- [License](#license)\n\n\n## Introduction\nThis module aims to provide an easy yet flexiable way to bind your PyroCMS Streams to a GraphQL API.\nThis module integrates `nuwave/lighthouse` with PyroCMS Streams.\n\nPlease make sure you have a basic understanding of:\n- [GraphQL](https://graphql.org/learn/)\n- [webonyx/graphql-php](http://webonyx.github.io/graphql-php/getting-started/)\n- [Lighthouse](https://lighthouse-php.netlify.com)\n\n## Preview\nA small usage preview of this module.\n\n### 1. Configure the bindings\n\n**config.php**\n```php\nreturn [\n    // other config options redacted, check out the documentation for a full overview\n    'default_field_resolutions' =\u003e [\n        'anomaly.field_type.addon'       =\u003e 'String',\n        'anomaly.field_type.blocks'      =\u003e 'String',\n        'anomaly.field_type.boolean'     =\u003e 'Boolean',\n        'anomaly.field_type.checkboxes'  =\u003e 'Boolean',\n        'anomaly.field_type.colorpicker' =\u003e 'String',\n        //etc...\n    ],\n    'stream_bindings'           =\u003e [\n        // namespace::slug\n        'users::users'                 =\u003e [\n\n            // generator results: type User {}\n            'type_name'   =\u003e 'User',\n\n            // PyroCMS Stream field assignment =\u003e GraphQL field type\n            'resolutions' =\u003e [\n                // custom type resolutions\n                'id'         =\u003e 'ID',\n                'roles'      =\u003e '[UserRole!] @hasMany',\n                'created_at' =\u003e 'Date',\n                'updated_at' =\u003e 'Date',\n                'deleted_at' =\u003e 'Date',\n\n                // The fields below will be resolved using the `default_field_resolutions`\n                // If you want, you can assign a custom type resolutions like above\n                'username',\n                'display_name',\n                'first_name',\n\n                // protect fields by requiring authentication and permissions\n                'email' =\u003e 'String @role(roles: [\"admin\"], operator: \"AND\")',\n                'email' =\u003e 'String @role(roles: [\"user\", \"guest\"], operator: \"NOT\")',\n                'email' =\u003e 'String @role(roles: [\"admin\", \"user\"], operator: \"OR\")',\n                'last_name',\n                'activated',\n                'enabled',\n            ],\n        ],\n        // other streams...\n    ]\n];\n\n```\n\n### 2. Generate the schema.graphql\n\nWhen you have defined all stream bindings and resolutions to your liking then you need to run the generator.\nThis will generate a GraphQL schema definition file that will be used by Lighthouse:\n\n```\nphp artisan api:generate\n```\n\n### 3. And voila!\n![GraphQL Query and Result](https://github.com/RobinRadic/graphql-streams-api/raw/master/screenshot.png)\n\n\n## Documentation\n\n### Installation\n\n**Add to composer**\n```\ncomposer require radic/graphql_streams_api-module\n```\n\n**Install addon**\n```\nphp artisan addon:install radic.module.graphql_streams_api\n```\n\n**Publish the addon**\n\nTo customize and define your GraphQL service use the `api:publish` command.\n\nThis will publish the configuration and schema files to `resources/{application}/addons/radic/graphql_streams_api`.\n\n```\nphp artisan api:publish\n```\n\n### Customization\nYou can customize/define the GraphQL service in `resources/{application}/addons/radic/graphql_streams_api`:\n- `config/config.php`\n- `schema/queryable.graphqls`\n- `schema/core.graphqls`\n\n#### config.schema\n- `output`  : The path where the schema will be generated.\n- `imports` : Paths to other schema definition files that will be included in the generated schema output.\n\n#### config.stream_bindings\nThis defines the streams that you want to be generated as GraphQL types.\n```php\n'stream_bindings' =\u003e [\n    // '{namespace}::{slug}'\n    'users::users' =\u003e [\n        'type_name'   =\u003e 'User', // The resulting GraphQL schema type name.\n        'resolutions' =\u003e [\n            'slug',\n            'title',\n            'roles' =\u003e '[UserRole!] @hasMany',\n        ]\n    ],\n    'users::roles' =\u003e [\n        'type_name'   =\u003e 'UserRole',\n        'resolutions' =\u003e [\n            'slug'\n        ]\n    ]\n]\n```\n\nThe `resolutions` are used to define the streams fields that should be in the GraphQL type.\nYou can either:\n- Define only stream field name (like 'slugs'). The generator will use the `default_field_bindings` to resolve the GraphQL type automatically.\n- Define the stream field name and a custom GraphQL field type. This is usually done with relationship fields or if you want to add some directive(s) to the field.\n\n### Generate\nAfter modifying the `config.php` or any of the defined `schema.imports` files you need to generate the output schema by running\n```\nphp artisan api:generate\n```\n\nThis will generate the schema in the configured `schema.output` file path.\n\n\n## License\n\nCopyright 2018 - Robin Radic - [MIT License](./LICENSE.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinradic%2Fgraphql-streams-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinradic%2Fgraphql-streams-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinradic%2Fgraphql-streams-api/lists"}