All Projects → caraus-ecms → Graphql

caraus-ecms / Graphql

Licence: bsd-3-clause
Haskell GraphQL implementation

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Graphql

Api Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Stars: ✭ 7,144 (+19744.44%)
Mutual labels:  graphql, graphql-server, graphql-api
Graph Node
Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
Stars: ✭ 884 (+2355.56%)
Mutual labels:  graphql, graphql-server, graphql-api
Rails Devise Graphql
A Rails 6 boilerplate to create your next Saas product. Preloaded with graphQL, devise, JWT, CanCanCan, RailsAdmin, Rubocop, Rspec, i18n and more.
Stars: ✭ 199 (+452.78%)
Mutual labels:  graphql, graphql-server, graphql-api
Gqlify
[NOT MAINTAINED]An API integration framework using GraphQL
Stars: ✭ 182 (+405.56%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphql Spqr
Java 8+ API for rapid development of GraphQL services
Stars: ✭ 843 (+2241.67%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphql Spqr Spring Boot Starter
Spring Boot 2 starter powered by GraphQL SPQR
Stars: ✭ 187 (+419.44%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphqlize
A Clojure & JVM library for developing GraphQL API instantly from Postgres and MySQL databases
Stars: ✭ 240 (+566.67%)
Mutual labels:  graphql, graphql-server, graphql-api
Hangzhou Graphql Party
杭州 GraphQLParty 往期记录(slide,照片,预告,视频等)
Stars: ✭ 142 (+294.44%)
Mutual labels:  graphql, graphql-server, graphql-api
Spikenail
A GraphQL Framework for Node.js
Stars: ✭ 358 (+894.44%)
Mutual labels:  graphql, graphql-server, graphql-api
Morpheus Graphql
Haskell GraphQL Api, Client and Tools
Stars: ✭ 285 (+691.67%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (+402.78%)
Mutual labels:  graphql, graphql-server, graphql-api
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (+1052.78%)
Mutual labels:  graphql, graphql-server, graphql-api
Storefront Api
Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends
Stars: ✭ 180 (+400%)
Mutual labels:  graphql, graphql-server, graphql-api
Grial
A Node.js framework for creating GraphQL API servers easily and without a lot of boilerplate.
Stars: ✭ 194 (+438.89%)
Mutual labels:  graphql, graphql-server, graphql-api
Pop
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (+344.44%)
Mutual labels:  graphql, graphql-server, graphql-api
36 Graphql Concepts
📜 36 concepts every GraphQL developer should know.
Stars: ✭ 209 (+480.56%)
Mutual labels:  graphql, graphql-server, graphql-api
Daptin
Daptin - Backend As A Service - GraphQL/JSON-API Headless CMS
Stars: ✭ 1,195 (+3219.44%)
Mutual labels:  graphql, graphql-server, graphql-api
Graphql Stack
A visual explanation of how the various tools in the GraphQL ecosystem fit together.
Stars: ✭ 117 (+225%)
Mutual labels:  graphql, graphql-server, graphql-api
Wp Graphql
🚀 GraphQL API for WordPress
Stars: ✭ 3,097 (+8502.78%)
Mutual labels:  graphql, graphql-server, graphql-api
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+53136.11%)
Mutual labels:  graphql, graphql-server, graphql-api

GraphQL implementation in Haskell

Hackage Version Hackage CI Build Status License Simple Haskell

This implementation is relatively low-level by design, it doesn't provide any mappings between the GraphQL types and Haskell's type system and avoids compile-time magic. It focuses on flexibility instead, so other solutions can be built on top of it.

State of the work

For now this library provides:

  • Parser for the query and schema languages, as well as a printer for the query language (minimizer and pretty-printer).
  • Data structures to define a type system.
  • Executor (queries, mutations and subscriptions are supported).
  • Validation is work in progress.
  • Introspection isn't available yet.

But the idea is to be a Haskell port of graphql-js.

For a more precise list of currently missing features see issues marked as "not implemented".

Documentation

API documentation is available through Hackage.

You'll also find a small tutorial with some examples under docs/tutorial.

Getting started

We start with a simple GraphQL API that provides us with some famous and less famous cites.

"""
Root Query type.
"""
type Query {
  """
  Provides a cite.
  """
  cite: String!
}

This is called a GraphQL schema, it defines all queries supported by the API. Query is the root query type. Every GraphQL API should define a query type.

Query has a single field cite that returns a String. The ! after the type denotes that the returned value cannot be Null. GraphQL fields are nullable by default.

To be able to work with this schema, we are going to implement it in Haskell.

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy.Char8 as ByteString.Lazy.Char8
import qualified Data.HashMap.Strict as HashMap
import Language.GraphQL
import Language.GraphQL.Type
import qualified Language.GraphQL.Type.Out as Out

-- GraphQL supports 3 kinds of operations: queries, mutations and subscriptions.
-- Our first schema supports only queries.
citeSchema :: Schema IO
citeSchema = schema queryType Nothing Nothing mempty

-- GraphQL distinguishes between input and output types. Input types are field
-- argument types and they are defined in Language.GraphQL.Type.In. Output types
-- are result types, they are defined in Language.GraphQL.Type.Out. Root types
-- are always object types.
--
-- Here we define a type "Query". The second argument is an optional
-- description, the third one is the list of interfaces implemented by the
-- object type. The last argument is a field map. Keys are field names, values
-- are field definitions and resolvers. Resolvers are the functions, where the
-- actual logic lives, they return values for the respective fields.
queryType :: Out.ObjectType IO
queryType = Out.ObjectType "Query" (Just "Root Query type.") []
    $ HashMap.singleton "cite" citeResolver
  where
    -- 'ValueResolver' is a 'Resolver' data constructor, it combines a field
    -- definition with its resolver function. This function resolves a value for
    -- a field (as opposed to the 'EventStreamResolver' used by subscriptions).
    -- Our resolver just returns a constant value.
    citeResolver = ValueResolver citeField
        $ pure "Piscis primum a capite foetat"

    -- The first argument is an optional field description. The second one is
    -- the field type and the third one is for arguments (we have none in this
    -- example).
    --
    -- GraphQL has named and wrapping types. String is a scalar, named type.
    -- Named types are nullable by default. To make our "cite" field
    -- non-nullable, we wrap it in the wrapping type, Non-Null.
    citeField = Out.Field
        (Just "Provides a cite.") (Out.NonNullScalarType string) HashMap.empty

-- Now we can execute a query. Since our schema defines only one field,
-- everything we can do is to ask to resolve it and give back the result.
-- Since subscriptions don't return plain values, the 'graphql' function returns
-- an 'Either'. 'Left' is for subscriptions, 'Right' is for queries and
-- mutations.
main :: IO ()
main = do
    Right result <- graphql citeSchema "{ cite }"
    ByteString.Lazy.Char8.putStrLn $ Aeson.encode result

Executing this query produces the following JSON:

{
  "data": {
    "cite": "Piscis primum a capite foetat"
  }
}

Further information

Contact

Suggestions, contributions and bug reports are welcome.

Should you have questions on usage, please open an issue and ask – this helps to write useful documentation.

Feel free to contact on Slack in #haskell on GraphQL. You can obtain an invitation here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].