Home

Home

Getting Started

GraphQL is a query language for API created by Facebook. See more complete documentation at http://graphql.org/. Looking for help? Find resources from the community.

An overview of GraphQL in general is available in the README for the Specification for GraphQL.

Diana.jl

Diana is a library that provides tools to implement a GraphQL API in Julia using both the code-first like Graphene (Python) approach and the schema-first like Ariadne (Python). Diana produces schemas that are fully compliant with the GraphQL spec.

This package is intended to help you building GraphQL schemas/types fast and easily.

Installation

Pkg> add Diana
#Release
pkg> add Diana#master
#Development

An example in Diana

Let’s build a basic GraphQL schema to say “hello” and “goodbye” in Diana.

using Diana

schema = Dict(
"query" => "Query"
,"Query"   => Dict(
    "hello"=>Dict("tipo"=>"String")
   ,"goodbye"=>Dict("tipo"=>"String")
   )
)

resolvers=Dict(
    "Query"=>Dict(
        "hello" => (root,args,ctx,info)->(return "Hello World!")
        ,"goodbye" => (root,args,ctx,info)->(return "Goodbye World")
    )
)

my_schema = Schema(schema, resolvers)

For each Field in our Schema, we write a Resolver method to fetch data requested by a client’s Query using the current context and Arguments.

Schema Definition Language (SDL)

In the GraphQL Schema Definition Language, we could describe the fields defined by our example code as show below.

using Diana

 schema= """
 type Query{
  hello: String
  goodbye: String
}
 schema {
  query: Query
}
"""

resolvers=Dict(
    "Query"=>Dict(
        "hello" => (root,args,ctx,info)->(return "Hello World!")
        ,"goodbye" => (root,args,ctx,info)->(return "Goodbye World")
    )
)

my_schema = Schema(schema, resolvers)

Querying

Then we can start querying our Schema by passing a GraphQL query string to execute:

query= """
query{
  hello
}
"""

result = my_schema.execute(query)

println(result)
# {"data":{"hello":"Hello World!"}}

Congrats! You got your first Diana schema working!

Manual

Functions

Tokensgraphql(x::String)

Given an origin string, this returns the set of tokens that make up that source.

source
Diana.ParseMethod.
Parse(str::String)

Given a GraphQL source, parses it into a AST. Throws Diana.GraphQLError if a syntax error is encountered.

source
Diana.QueryclientMethod.
Queryclient(queryurl::String)

Execute the query in link format and return the result.

source
Diana.QueryclientMethod.
Queryclient(url::String,data::String; vars::Dict=Dict(),auth::String="Bearer 0000", headers::Dict=Dict(),getlink::Bool=false,check::Bool=false,operationName::String="")

Execute a query with all available parameters

source
GraphQLClient(url::String; auth::String="Bearer 0000", headers::Dict=Dict())

Stores the parameters of the query for later use, returns a Client object

source
Diana.SchemaMethod.
Schema(_schema::String, resolvers::Dict; context=nothing)

Receive a schema in string format or in a text file, return an object of type schema

source
Diana.SchemaMethod.
Schema(_schema::Dict, resolvers::Dict; context=nothing)

Receive a schema in dictionary format, return an object of type schema

source

Index