Skip to content

Easily serve a GraphQL API for your Symfony application in as few as three easy steps!

License

Notifications You must be signed in to change notification settings

Wedrix/watchtower-symfony-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The WedrixWatchtowerBundle allows you to easily serve a GraphQL API for a Symfony application in as few as three easy steps. It is based on Watchtower, a wrapper around graphql-php, that provides an enhanced fallback resolver capable of auto-resolving GraphQL queries using the Doctrine schema.

Requirements

This bundle is only compatible with Symfony versions >=6.1.

Installation

Install the bundle in three easy steps:

  1. Enable recipes defined in the contrib repository:

     composer config extra.symfony.allow-contrib true
    
  2. Install the bundle:

     composer require wedrix/watchtower-bundle
    
  3. Generate the GrahQL schema:

     php bin/console watchtower:schema:generate
    

That's it! Your GraphQL API is now available at whatever-your-domain-is/graphql.json by default.

Note: When accessing the API over a web browser you may need to enable CORS if it is not already enabled for your application. To do so, kindly view the NelmioCorsBundle documentation for the installation and setup guide. You may also view the demo application's source code for a quick-and-dirty example configuration after installing the bundle.

Features

For a complete list of features kindly view the Watchtower documentation.

Config Options

The various configuration options are available in the config/packages/wedrix_watchtower_bundle.yaml file:

  • endpoint - configures the enpoint for accessing the GraphQL API (/graphql.json by default).
  • schema_file - configures the file used as the source of the GraphQL schema (auto-generated using the php bin/console watchtower:schema:generate command). You may point it to a pre-existing schema file if your project already has one.
  • plugins_directory - configures the directory containing your various plugins: filters, selectors, resolvers, etc. Kindly view the Watchtower documentation for more info on plugins.
  • scalar_type_definitions_directory - configures the directory containing your various scalar type definition files. Kindly view the Watchtower documentation for more info on scalar type definitions.
  • cache_directory - the directory for storing caches.
  • optimize - whether to run in optimized mode. This improves the performance but may be annoying in development since it necessitates regenerating the cache whenever you make changes to the schema or add new plugins or scalar type definitions.
  • debug - whether to send debug information to the client. Most of the time, this should only be enabled in development environments but the configuration is exposed for those who want to take their chances debugging production environemnts.
  • context - this allows you access any service in the container in plugins using the Node::context() method. The service key can be any name of your choosing but the value should be the service id. For example: entity_manager: 'doctrine.orm.entity_manager'.

Available Commands

  • watchtower:plugins:add - used to generate the boilerplate for plugins. Kindly view the Watchtower documentation for more info on plugins.
  • watchtower:scalar-type-definitions:add - used to generate the boilderplate for scalar type definitions. Kindly view the Watchtower documentation for more info on scalar type definitions.
  • watchtower:schema:generate - used to generate the GraphQL schema file based on the Doctrine schema.
  • watchtower:plugins:list - lists all the configured plugins. Kindly view the Watchtower documentation for more info on plugins.
  • watchtower:scalar-type-definitions:list - lists all the configured scalar type definitions. Kindly view the Watchtower documentation for more info on scalar type definitions.
  • watchtower:schema:update - used to update the GraphQL schema file based on the current Doctrine schema.
  • watchtower:cache:generate - used to generate the updated cache.

About

Easily serve a GraphQL API for your Symfony application in as few as three easy steps!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages