fsprojects/FSharp.Data.GraphQL

Name: FSharp.Data.GraphQL

Owner: F# Community Project Incubation Space

Description: FSharp implementation of Facebook GraphQL query language.

Created: 2016-04-01 21:01:56.0

Updated: 2018-05-17 11:58:16.0

Pushed: 2018-05-21 19:14:21.0

Homepage: http://fsprojects.github.io/FSharp.Data.GraphQL/

Size: 2727

Language: F#

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

FSharp.Data.GraphQL

F# implementation of Facebook GraphQL query language specification.

Build Status Build status

Quick start
 Person = 
{ FirstName: string
  LastName: string }

efine GraphQL type 
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 })   
])

nclude person as a root query of a schema
schema = Schema(query = PersonType)

etrieve person data
johnSnow = { FirstName = "John"; LastName = "Snow" }
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 and run FSharp.Data.GraphQL.Samples.GiraffeServer project on Debug settings - this will create a Giraffe server compatible with GraphQL spec, running on port 8084. 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 editor should appear. You may try it by applying following query:


ro(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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.