Skip to content

Commit

Permalink
Add Cro::HTTP::Router::GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtTilmes committed Nov 13, 2017
1 parent a788868 commit 8022e78
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "GraphQL",

"version" : "0.5.3",
"version" : "0.5.4",

"source-url" : "https://github.com/CurtTilmes/Perl6-GraphQL.git",

Expand All @@ -20,10 +20,11 @@
"GraphQL::Response" : "lib/GraphQL/Response.pm",
"GraphQL::Server" : "lib/GraphQL/Server.pm",
"GraphQL::Types" : "lib/GraphQL/Types.pm",
"GraphQL::Validation" : "lib/GraphQL/Validation.pm"
"GraphQL::Validation" : "lib/GraphQL/Validation.pm",
"Cro::HTTP::Router::GraphQL" : "lib/Cro/HTTP/Router/GraphQL.pm6",
},

"depends" : [ "JSON::Fast", "Text::Wrap", "Bailador" ],
"depends" : [ "JSON::Fast", "Text::Wrap" ],

"description" : "Perl6 implementation of GraphQL",

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ You can use that to explore the schema (though the Hello World schema
is very simple, that won't take long), and interactively construct and
execute GraphQL queries.

## Embedding in a Cro server

As an alternative to Bailador, you can use Cro::HTTP::Router::GraphQL
to embed GraphQL into [Cro](http://mi.cro.services/) HTTP routes:

```
use Cro::HTTP::Router::GraphQL;
route {
get -> 'graphql' { graphiql}
post -> 'graphql' { graphql(GraphQL::Schema.new(...)) }
}
```

You can mix/match with other routes you want your server to handle.

## More documentation

See [eg/usersexample.md](/eg/usersexample.md) for a more complicated example.
Expand Down
15 changes: 15 additions & 0 deletions lib/Cro/HTTP/Router/GraphQL.pm6
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use Cro::HTTP::Router;
use GraphQL::GraphiQL;
use GraphQL;

sub graphiql() is export {
content 'text/html', $GraphiQL;
}

sub graphql(GraphQL::Schema $schema) is export {
request-body -> % (:$query, :$operationName = Str, :$variables)
{
content 'application/json', $schema.execute($query,
:$operationName, variables => $variables // %()).to-json;
}
}

0 comments on commit 8022e78

Please sign in to comment.