Giter VIP home page Giter VIP logo

Comments (6)

janicduplessis avatar janicduplessis commented on September 9, 2024

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.

janicduplessis avatar janicduplessis commented on September 9, 2024

I could also use jsAreaType where I'd use a normal type in JS

from bs-graphql-js.

janicduplessis avatar janicduplessis commented on September 9, 2024

For promises you need to use asyncField instead of field.

from bs-graphql-js.

thangngoc89 avatar thangngoc89 commented on September 9, 2024

@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.

janicduplessis avatar janicduplessis commented on September 9, 2024

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.

thangngoc89 avatar thangngoc89 commented on September 9, 2024

@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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.