Comments (6)
Here's a file from the project I'm using this on.
open BsGraphqlJs.Schema;
module Connection = BsGraphqlJs.Relay.Connection(TwJs.Handler.Context);
let neighborhoodType =
obj(
"Neighborhood",
~fields=
lazy [
field("name", ~typ=nonNull(string), ~args=[], ~resolve=(_ctx, node) =>
node##name
),
],
);
let areaType =
obj(
"Area",
~fields=
lazy [
field("id", ~typ=nonNull(string), ~args=[], ~resolve=(_ctx, node) =>
node##id
),
field("name", ~typ=nonNull(string), ~args=[], ~resolve=(_ctx, node) =>
node##name
),
field(
"coords",
~typ=nonNull(QueryTypes.locationType),
~args=[],
~resolve=(_ctx, node) =>
node##coords
),
field("image", ~typ=string, ~args=[], ~resolve=(_ctx, node) =>
Js.toOption(node##image)
),
field("typo", ~typ=string, ~args=[], ~resolve=(_ctx, node) =>
Js.toOption(node##typo)
),
field(
"neighborhoods",
~typ=QueryTypes.nonNullList(neighborhoodType),
~args=[],
~resolve=(_ctx, node) =>
node##neighborhoods
),
...QueryTypes.entityFields(),
],
);
let {Connection.connectionType} =
Connection.definitions("Area", ~nodeType=areaType);
let areasField: field(TwJs.Handler.Context.t, unit) =
asyncField(
"areas",
~typ=nonNull(connectionType),
~args=Connection.forwardsArgs(),
~resolve=(ctx, _node, first, after) =>
AreaService.findConnection(ctx, ~connectionArgs={first, after})
);
let jsAreaType = toJsType(areaType);
let jsAreasField = toJsSchema(areasField);
then in JS:
import { jsAreasField } from './AreaQuery.bs';
...
export const ViewerType = new GraphQLObjectType({
name: 'Viewer',
fields: () => ({
...
areas: jsAreasField,
});
I'm using graphql-js but I assume it should work with ApolloServer too.
from bs-graphql-js.
I could also use jsAreaType where I'd use a normal type in JS
from bs-graphql-js.
For promises you need to use asyncField
instead of field
.
from bs-graphql-js.
@janicduplessis Ahhhh. I get it now. Thank you so much. So you're using this to build toplevel queries. and then stitching them together in JS.
from bs-graphql-js.
Yes, I built this as an interop layer to be able to progressively integrate Reason schemas as part of a existing JS schema. It should be possible to build a full Reason schema with it too but I havenโt tried that yet.
from bs-graphql-js.
@janicduplessis yes, i was hacking the type like crazy (lots of %identity) to be able to write eveything in ReasonML.
from bs-graphql-js.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bs-graphql-js.