Skip to content

Commit

Permalink
Merge pull request #6 from Coobaha/1.0
Browse files Browse the repository at this point in the history
Print all possible resolvers
  • Loading branch information
Coobaha authored Feb 1, 2019
2 parents 81ed4ae + e708da6 commit 1da2994
Show file tree
Hide file tree
Showing 36 changed files with 21,629 additions and 528 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
_build
_release
_esy
esy.lock
*.log
*.byte
*.native
Expand Down
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ os:
- linux
- osx

env:
- NODE_ENV=production

before_install:
- npm install --global esy@latest
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export TARGET_NAME=darwin-x64; fi
Expand All @@ -25,11 +22,12 @@ cache:

install:
- esy install
- cd test && yarn install && cd ..
- yarn
- cd test && yarn && cd ..

script:
- esy build
- esy test
- make test
- mv _build/default/graphql_to_reason.exe graphql-to-reason-$TARGET_NAME.exe

deploy:
Expand Down
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@
> - :house: [Internal]
> - :nail_care: [Polish]
## 1.0.0-alpha.0 - 2018-01.02

- :rocket: All possible resolvers are now being printed
- :boom: SchemaConfig.resolver type was changed, now it accepts parent type
- :boom: Module names for Query, Mutation and Subscription are now singular instead of plural (Queries -> Query)

### Breaking changes

SchemaConfig.resolver type was changed, it now accepts parent type

```diff
- type resolver('args, 'fieldType, 'result) =
- (unit, 'args) => Js.Promise.t('result);
+ type resolver('parent, 'args, 'fieldType, 'result) =
+ ('parent, 'args) => Js.Promise.t('result);
```

Module names for Query, Mutation and Subscription are now singular instead of plural (i.e. Queries -> Query)

```diff
-let query =
- SchemaTypes.Queries.t(
- ~article=Articles.getByIdResolver,
- ~articles=Articles.resolver,
+let resolvers: SchemaTypes.t =
+ SchemaTypes.t(
+ ~query=
+ SchemaTypes.Query.t(
+ ~article=Articles.getByIdResolver,
+ ~articles=Articles.resolver,
+ (),
+ ),
+ ~mutation=SchemaTypes.Mutation.t(~addArticle=Articles.addArticle, ()),
+ ~comment=SchemaTypes.Comment.t(~content=Articles.Comments.content, ()),
(),
);
-
-let mutation = SchemaTypes.Mutations.t(~addArticle=Articles.addArticle, ());
```

## 0.4.1 - 2018-11-03
- :nail_care: Refactor where __typename is filtered

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ include SchemaTypes_builder.MakeSchema({
unit,
'args,
/*context args depend on your graphql setup*/
ServerContext.GraphqlContext.t,
ServerContext.t,
ServerContext.ResolveInfo.t,
ServerContext.FieldInfo.t('fieldType)
) =>
Expand All @@ -136,12 +136,13 @@ module Clicks = {
};


/* Clicks.resolver now infers SchemaTypes.Mutation.clicksCount type */
let mutationResolvers =
SchemaTypes.Mutations.t(
/* Clicks.resolver now infers SchemaTypes.Mutations.clicksCount type */
~clicksCount=Clicks.resolver,
(),
);
SchemaTypes.Mutation.t(~clicksCount=Clicks.resolver, ());

let resolvers = SchemaTypes.t(~mutation, ());

createMyGraphqlServer(resolvers);
```


Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ build_script:
- esy build

test_script:
- esy test
- make test
35 changes: 31 additions & 4 deletions examples/basic/src/Articles.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
open Js;

let (articles, nextId) = {
let a = Dict.empty();
a->Dict.set("1", {"id": "1", "title": "First", "body": "Hello world"});
a->Dict.set("2", {"id": "2", "title": "Second", "body": "Hello world"});
let a: Dict.t(SchemaTypes.article) = Dict.empty();
a->Dict.set(
"1",
{
"id": "1",
"title": "First",
"body": "Hello world",
"comments": [|{"content": "First comment"}|]->Nullable.return,
},
);
a->Dict.set(
"2",
{
"id": "2",
"title": "Second",
"body": "Hello world",
"comments": Nullable.null,
},
);
(a, ref(3));
};

Expand All @@ -14,8 +30,19 @@ let resolver = (_node, _args) => articles->Dict.values->Promise.resolve;

let addArticle = (_node, args) => {
let id = string_of_int(nextId^);
let article = {"id": id, "title": args##title, "body": args##body};
let article = {
"id": id,
"title": args##title,
"body": args##body,
"comments": Js.Nullable.null,
};
articles->Dict.set(id, article);
incr(nextId);
article->Nullable.return->Promise.resolve;
};

module Comments = {
let content = (parent, _args) => {
Promise.resolve(parent##content ++ "!!!!!");
};
};
16 changes: 10 additions & 6 deletions examples/basic/src/Resolvers.re
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
let query =
SchemaTypes.Queries.t(
~article=Articles.getByIdResolver,
~articles=Articles.resolver,
let resolvers: SchemaTypes.t =
SchemaTypes.t(
~query=
SchemaTypes.Query.t(
~article=Articles.getByIdResolver,
~articles=Articles.resolver,
(),
),
~mutation=SchemaTypes.Mutation.t(~addArticle=Articles.addArticle, ()),
~comment=SchemaTypes.Comment.t(~content=Articles.Comments.content, ()),
(),
);

let mutation = SchemaTypes.Mutations.t(~addArticle=Articles.addArticle, ());
5 changes: 2 additions & 3 deletions examples/basic/src/SchemaTypes.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include SchemaTypes_builder.MakeSchema({
module Scalars = {};
type resolver('args, 'fieldType, 'result) =
(unit, 'args) => Js.Promise.t('result);
type resolver('parent, 'args, 'fieldType, 'result) =
('parent, 'args) => Js.Promise.t('result);
type directiveResolver('payload);
});

58 changes: 49 additions & 9 deletions examples/basic/src/SchemaTypes_builder.re
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
module type SchemaConfig = {
module Scalars: {};
type resolver('payload, 'fieldType, 'result);
type resolver('parent, 'payload, 'fieldType, 'result);
type directiveResolver('payload);
};
module MakeSchema = (Config: SchemaConfig) => {
include Config.Scalars;
type resolver('payload, 'fieldType, 'result) =
Config.resolver('payload, 'fieldType, 'result);
type rootResolver('payload, 'fieldType, 'result) =
Config.resolver(unit, 'payload, 'fieldType, 'result);
type directiveResolver('payload) = Config.directiveResolver('payload);
type mutation = {. "addArticle": Js.Nullable.t(article)}
and query = {
.
"article": Js.Nullable.t(article),
"articles": array(article),
}
and comment = {. "content": string}
and article = {
.
"id": string,
"title": string,
"body": string,
"comments": Js.Nullable.t(array(comment)),
};
module Queries = {
module Query = {
[@bs.deriving abstract]
type t = {
[@bs.optional]
article: resolver({. "id": string}, article, Js.Nullable.t(article)),
article:
rootResolver({. "id": string}, article, Js.Nullable.t(article)),
[@bs.optional]
articles: resolver(unit, article, array(article)),
articles: rootResolver(unit, article, array(article)),
};
};
module Mutations = {
module Mutation = {
[@bs.deriving abstract]
type t = {
[@bs.optional]
addArticle:
resolver(
rootResolver(
{
.
"title": string,
Expand All @@ -45,7 +48,7 @@ module MakeSchema = (Config: SchemaConfig) => {
),
};
};
module Subscriptions = {};
module Subscription = {};
module Directives = {
[@bs.deriving abstract]
type t = {
Expand All @@ -57,4 +60,41 @@ module MakeSchema = (Config: SchemaConfig) => {
deprecated: directiveResolver({. "reason": Js.Nullable.t(string)}),
};
};
module Article = {
[@bs.deriving abstract]
type t = {
[@bs.optional]
id: Config.resolver(article, unit, string, string),
[@bs.optional]
title: Config.resolver(article, unit, string, string),
[@bs.optional]
body: Config.resolver(article, unit, string, string),
[@bs.optional]
comments:
Config.resolver(
article,
unit,
comment,
Js.Nullable.t(array(comment)),
),
};
};
module Comment = {
[@bs.deriving abstract]
type t = {
[@bs.optional]
content: Config.resolver(comment, unit, string, string),
};
};
[@bs.deriving abstract]
type t = {
[@bs.optional] [@bs.as "Article"]
article: Article.t,
[@bs.optional] [@bs.as "Comment"]
comment: Comment.t,
[@bs.optional] [@bs.as "Query"]
query: Query.t,
[@bs.optional] [@bs.as "Mutation"]
mutation: Mutation.t,
};
};
7 changes: 1 addition & 6 deletions examples/basic/src/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { query, mutation } from './Resolvers.bs'

const resolvers = {
Query: query,
Mutation: mutation,
};
import { resolvers } from './Resolvers.bs'

export default resolvers;
5 changes: 5 additions & 0 deletions examples/basic/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ type Article {
id: String!
title: String!
body: String!
comments: [Comment!]
}

type Comment {
content: String!
}

type Query {
Expand Down
47 changes: 47 additions & 0 deletions examples/basic/src/schema.graphql.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,53 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "comments",
"description": "",
"args": [],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Comment",
"ofType": null
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Comment",
"description": "",
"fields": [
{
"name": "content",
"description": "",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
Loading

0 comments on commit 1da2994

Please sign in to comment.