Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 156fba1
Showing
12 changed files
with
1,141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/.build/ | ||
/_build/ | ||
/Build | ||
/Build.bat | ||
/blib | ||
/Makefile | ||
/pm_to_blib | ||
|
||
/carton.lock | ||
/.carton/ | ||
/local/ | ||
|
||
nytprof.out | ||
nytprof/ | ||
|
||
cover_db/ | ||
|
||
*.bak | ||
*.old | ||
*~ | ||
*.swp | ||
*.o | ||
*.obj | ||
|
||
!LICENSE | ||
|
||
/_build_params | ||
|
||
MYMETA.* | ||
|
||
/GraphQL-Plugin-Convert-OpenAPI-* | ||
|
||
/MANIFEST.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
language: perl | ||
sudo: false | ||
perl: | ||
- "5.14.0" | ||
- "5.22.0" | ||
matrix: | ||
include: | ||
- perl: "5.22.0" | ||
env: AUTHOR_TESTING=1 RELEASE_TESTING=1 | ||
# env: COVERAGE=1 | ||
before_install: | ||
- git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers | ||
- source ~/travis-perl-helpers/init | ||
- build-perl | ||
- local-lib cache | ||
- perl -V | ||
- build-dist | ||
- cd $BUILD_DIR # $BUILD_DIR is set by the build-dist command | ||
install: | ||
- cpan-install --deps # installs prereqs, including recommends | ||
# - cpan-install --coverage # installs converage prereqs, if enabled | ||
#before_script: | ||
# - coverage-setup | ||
script: | ||
- prove -l -j$(test-jobs) $(test-files) # parallel testing | ||
#after_success: | ||
# - coverage-report | ||
notifications: | ||
irc: | ||
channels: | ||
- "irc.perl.org#graphql-perl" | ||
on_failure: always | ||
skip_join: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Revision history for Perl extension GraphQL-Plugin-Convert-OpenAPI | ||
|
||
0.01 | ||
- first version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Changes | ||
lib/GraphQL/Plugin/Convert/OpenAPI.pm | ||
Makefile.PL | ||
MANIFEST This list of files | ||
README.md | ||
t/00-compile.t | ||
t/00-report-prereqs.t | ||
xt/manifest.t | ||
xt/pod.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MANIFEST.SKIP | ||
MANIFEST.bak | ||
.git\/ | ||
^.gitignore | ||
^.travis.yml | ||
blib\/ | ||
MYMETA\..* | ||
^GraphQL-Plugin-Convert-OpenAPI-\d.* | ||
^Makefile$ | ||
^Makefile.bak$ | ||
pm_to_blib | ||
\.swp$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use 5.008001; | ||
use strict; | ||
use warnings; | ||
use ExtUtils::MakeMaker; | ||
|
||
WriteMakefile( | ||
NAME => 'GraphQL::Plugin::Convert::OpenAPI', | ||
AUTHOR => q{Ed J <etj@cpan.org>}, | ||
VERSION_FROM => 'lib/GraphQL/Plugin/Convert/OpenAPI.pm', | ||
ABSTRACT_FROM => 'lib/GraphQL/Plugin/Convert/OpenAPI.pm', | ||
LICENSE => 'artistic_2', | ||
MIN_PERL_VERSION => '5.014', | ||
CONFIGURE_REQUIRES => { | ||
'ExtUtils::MakeMaker' => '0', | ||
}, | ||
TEST_REQUIRES => { | ||
'Test::More' => '0.98', | ||
}, | ||
PREREQ_PM => { | ||
'JSON::Validator' => 0, | ||
'GraphQL' => '0.21', # DateTime scalar type | ||
}, | ||
clean => { FILES => 'GraphQL-Plugin-Convert-OpenAPI-*' }, | ||
META_MERGE => { | ||
"meta-spec" => { version => 2 }, | ||
dynamic_config => 0, | ||
resources => { | ||
x_IRC => 'irc://irc.perl.org/#graphql-perl', | ||
repository => { | ||
type => 'git', | ||
url => 'git@github.com:graphql-perl/GraphQL-Plugin-Convert-OpenAPI.git', | ||
web => 'https://github.com/graphql-perl/GraphQL-Plugin-Convert-OpenAPI', | ||
}, | ||
bugtracker => { | ||
web => 'https://github.com/graphql-perl/GraphQL-Plugin-Convert-OpenAPI/issues', | ||
}, | ||
license => [ 'http://dev.perl.org/licenses/' ], | ||
}, | ||
prereqs => { | ||
develop => { | ||
requires => { | ||
'Test::CheckManifest' => '0.9', | ||
'Test::Pod' => '1.22', | ||
'Pod::Markdown' => 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
sub MY::postamble { | ||
<<EOF; | ||
pure_all :: README.md | ||
README.md : lib/GraphQL/Plugin/Convert/OpenAPI.pm | ||
\tpod2markdown \$< >\$\@ | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# NAME | ||
|
||
GraphQL::Plugin::Convert::OpenAPI - convert OpenAPI schema to GraphQL schema | ||
|
||
# PROJECT STATUS | ||
|
||
| OS | Build status | | ||
|:-------:|--------------:| | ||
| Linux | [![Build Status](https://travis-ci.org/graphql-perl/GraphQL-Plugin-Convert-OpenAPI.svg?branch=master)](https://travis-ci.org/graphql-perl/GraphQL-Plugin-Convert-OpenAPI) | | ||
|
||
[![CPAN version](https://badge.fury.io/pl/GraphQL-Plugin-Convert-OpenAPI.svg)](https://metacpan.org/pod/GraphQL::Plugin::Convert::OpenAPI) | ||
|
||
# SYNOPSIS | ||
|
||
use GraphQL::Plugin::Convert::OpenAPI; | ||
use Schema; | ||
my $converted = GraphQL::Plugin::Convert::OpenAPI->to_graphql( | ||
sub { Schema->connect } | ||
); | ||
print $converted->{schema}->to_doc; | ||
|
||
# DESCRIPTION | ||
|
||
This module implements the [GraphQL::Plugin::Convert](https://metacpan.org/pod/GraphQL::Plugin::Convert) API to convert | ||
a [JSON::Validator::OpenAPI](https://metacpan.org/pod/JSON::Validator::OpenAPI) to [GraphQL::Schema](https://metacpan.org/pod/GraphQL::Schema) etc. | ||
|
||
## Example | ||
|
||
Consider this minimal data model: | ||
|
||
blog: | ||
id # primary key | ||
articles # has_many | ||
title # non null | ||
language # nullable | ||
article: | ||
id # primary key | ||
blog # foreign key to Blog | ||
title # non null | ||
content # nullable | ||
|
||
## Generated Output Types | ||
|
||
These [GraphQL::Type::Object](https://metacpan.org/pod/GraphQL::Type::Object) types will be generated: | ||
|
||
type Blog { | ||
id: Int! | ||
articles: [Article] | ||
title: String! | ||
language: String | ||
} | ||
|
||
type Article { | ||
id: Int! | ||
blog: Blog | ||
title: String! | ||
content: String | ||
} | ||
|
||
type Query { | ||
blog(id: [Int!]!): [Blog] | ||
article(id: [Int!]!): [Blog] | ||
} | ||
|
||
Note that while the queries take a list, the return order is | ||
undefined. This also applies to the mutations. If this matters, request | ||
the primary key fields and use those to sort. | ||
|
||
## Generated Input Types | ||
|
||
Different input types are needed for each of CRUD (Create, Read, Update, | ||
Delete). | ||
|
||
The create one needs to have non-null fields be non-null, for idiomatic | ||
GraphQL-level error-catching. The read one needs all fields nullable, | ||
since this will be how searches are implemented, allowing fields to be | ||
left un-searched-for. Both need to omit primary key fields. The read | ||
one also needs to omit foreign key fields, since the idiomatic GraphQL | ||
way for this is to request the other object, with this as a field on it, | ||
then request any required fields of this. | ||
|
||
Meanwhile, the update and delete ones need to include the primary key | ||
fields, to indicate what to mutate, and also all non-primary key fields | ||
as nullable, which for update will mean leaving them unchanged, and for | ||
delete is to be ignored. | ||
|
||
Therefore, for the above, these input types (and an updated Query, | ||
and Mutation) are created: | ||
|
||
input BlogCreateInput { | ||
title: String! | ||
language: String | ||
} | ||
|
||
input BlogSearchInput { | ||
title: String | ||
language: String | ||
} | ||
|
||
input BlogMutateInput { | ||
id: Int! | ||
title: String | ||
language: String | ||
} | ||
|
||
input ArticleCreateInput { | ||
blog_id: Int! | ||
title: String! | ||
content: String | ||
} | ||
|
||
input ArticleSearchInput { | ||
title: String | ||
content: String | ||
} | ||
|
||
input ArticleMutateInput { | ||
id: Int! | ||
title: String! | ||
language: String | ||
} | ||
|
||
type Mutation { | ||
createBlog(input: [BlogCreateInput!]!): [Blog] | ||
createArticle(input: [ArticleCreateInput!]!): [Article] | ||
deleteBlog(input: [BlogMutateInput!]!): [Boolean] | ||
deleteArticle(input: [ArticleMutateInput!]!): [Boolean] | ||
updateBlog(input: [BlogMutateInput!]!): [Blog] | ||
updateArticle(input: [ArticleMutateInput!]!): [Article] | ||
} | ||
|
||
extends type Query { | ||
searchBlog(input: BlogSearchInput!): [Blog] | ||
searchArticle(input: ArticleSearchInput!): [Article] | ||
} | ||
|
||
# ARGUMENTS | ||
|
||
To the `to_graphql` method: a code-ref returning a [DBIx::Class::Schema](https://metacpan.org/pod/DBIx::Class::Schema) | ||
object. This is so it can be called during the conversion process, | ||
but also during execution of a long-running process to e.g. execute | ||
database queries, when the database handle passed to this method as a | ||
simple value might have expired. | ||
|
||
# PACKAGE FUNCTIONS | ||
|
||
## field\_resolver | ||
|
||
This is available as `\&GraphQL::Plugin::Convert::OpenAPI::field_resolver` | ||
in case it is wanted for use outside of the "bundle" of the `to_graphql` | ||
method. | ||
|
||
# DEBUGGING | ||
|
||
To debug, set environment variable `GRAPHQL_DEBUG` to a true value. | ||
|
||
# AUTHOR | ||
|
||
Ed J, `<etj at cpan.org>` | ||
|
||
# LICENSE | ||
|
||
Copyright (C) Ed J | ||
|
||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself. |
Oops, something went wrong.