rmosolgo/graphql-ruby

Confusing documentation for plugins

rex-remind101 opened this issue · 1 comments

Describe the bug

There is a hint of documentation about writing Plugin but no detailed description of what interface or class to inherit to do so https://graphql-ruby.org/schema/definition.html#plugins . I'd like to write a plugin for some connection management but cannot figure out how.

Versions

latest

GraphQL schema

n/a

GraphQL query

n/a

Steps to reproduce

https://graphql-ruby.org/schema/definition.html#plugins

Expected behavior

There's clear documentation on how to implement a plugin.

Actual behavior

There's not clear documentation on how to implement a plugin.

n/a

Additional context

n/a

Hi! Sorry for the confusion and thanks for asking about it. In short, use ... is an API for adding things to your schema. Whatever object is passed to use ... receives a method call like .use(schema, **kwargs), and inside that method, it can do whatever it wants to the passed-in schema.

There's not anything else special about plugins (yet...?), beside that .use call. So you can see a few examples inside GraphQL-Ruby:

def self.use(schema_defn)
schema_defn.trace_with(self::Trace)
end

def self.use(schema, preload: nil, migration_errors: false)
schema.visibility = self.new(schema, preload: preload)
schema.use_schema_visibility = true
if migration_errors
schema.subset_class = Migration
end
end

class Timeout
def self.use(schema, max_seconds: nil)
timeout = self.new(max_seconds: max_seconds)
schema.trace_with(self::Trace, timeout: timeout)
end

def self.use(defn, options = {})
schema = defn.is_a?(Class) ? defn : defn.target
if schema.subscriptions(inherited: false)
raise ArgumentError, "Can't reinstall subscriptions. #{schema} is using #{schema.subscriptions}, can't also add #{self}"
end

So, there's not really more to say about that. Arguably, that section could be removed from the docs entirely since it's not useful by itself. (That is, all the relevant plugins have documentation for use ...).

If you give that API a try and run into any trouble, please let me know!