Giter VIP home page Giter VIP logo

fsharp.data.graphql's Introduction

FSharp.Data.GraphQL

F# implementation of Facebook GraphQL query language specification.

Build Status Build status

Quick start

type Person = 
    { FirstName: string
      LastName: string }

// define GraphQL type 
let PersonType = Define.Object(
    name = "Person",
    fields = [
        // property resolver will be auto-generated
        Define.AutoField("firstName", String)   
        // asynchronous explicit member resolver
        Define.AsyncField("lastName", String, resolve = fun context person -> async { return person.LastName })   
    ])
    
// include person as a root query of a schema
let schema = Schema(query = PersonType)

// retrieve person data
let johnSnow = { FirstName = "John"; LastName = "Snow" }
let reply = schema.AsyncExecute(parse "{ firstName, lastName }", johnSnow) |> Async.RunSynchronously
// #> { data: { "firstName", "John", "lastName", "Snow" } } 

It's type safe. Things like invalid fields or invalid return types will be checked at compile time.

Demos

GraphiQL client

Go to GraphiQL sample directory. In order to run it, build FSharp.Data.GraphQL project on Debug settings and run server.fsx with FSI - this will create a Suave.IO server compatible with GraphQL spec, running on port 8083. Then what you need is to run node.js graphiql frontend. To do so, run npm i to get all dependencies, and then run npm run serve | npm run dev - this will start a webpack server running on http://localhost:8090/ . Visit this link, and GraphiQL edito should appear. You may try it by applying following query:

{
  hero(id:"1000") {
    id,
    name,
    appearsIn,
    homePlanet,
    friends {
      ... on Human {
        name
      }
      ... on Droid {
        name
      }
    }
  }
}

Relay.js starter kit

Second sample is a F#-backed version of of popular Relay Starter Kit - an example application using React.js + Relay with Relay-compatible server API.

To run it, build a FSharp.Data.GraphQL and FSharp.Data.GraphQL.Relay projects using Debug settings. Then start server by running server.fsx script in your FSI - this will start relay-compatible F# server on port 8083. Then build node.js frontend by getting all dependencies (npm i) and running it (npm run serve | npm run dev) - this will start webpack server running React application using Relay for managing application state. You can visit it on http://localhost:8083/ .

In order to update client schema, visit http://localhost:8083/ and copy-paste the response (which is introspection query result from current F# server) into data/schema.json.

fsharp.data.graphql's People

Contributors

alexpantyukhin avatar alfonsogarciacaro avatar horusiath avatar johnberzy-bazinga avatar olegzee avatar

Watchers

 avatar  avatar

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.