All Projects → Vincit → Venia

Vincit / Venia

Licence: epl-1.0
Clojure(Script) graphql query generation

Programming Languages

clojure
4091 projects
clojurescript
191 projects

Labels

Projects that are alternatives of or similar to Venia

Graphql Normalizr
Normalize GraphQL responses for persisting in the client cache/state
Stars: ✭ 175 (-2.23%)
Mutual labels:  graphql
Bigdata Playground
A complete example of a big data application using : Kubernetes (kops/aws), Apache Spark SQL/Streaming/MLib, Apache Flink, Scala, Python, Apache Kafka, Apache Hbase, Apache Parquet, Apache Avro, Apache Storm, Twitter Api, MongoDB, NodeJS, Angular, GraphQL
Stars: ✭ 177 (-1.12%)
Mutual labels:  graphql
Fetchql
GraphQL client with Fetch
Stars: ✭ 178 (-0.56%)
Mutual labels:  graphql
Gatsby Wordpress Themes
🎨 Gatsby WordPress Theme
Stars: ✭ 175 (-2.23%)
Mutual labels:  graphql
Feathers Apollo
Feathers and Apollo Server Sample Project
Stars: ✭ 176 (-1.68%)
Mutual labels:  graphql
Jamstack Serverless
Learn JAMstack Serverless Modern App Development in Baby Steps using Gatsby.js, React, TypeScript, GraphQL, Contentful, Netlify, FaunaDB, MongoDB, Apollo, Github Actions, Project Fugu, and CSS Houdini.
Stars: ✭ 178 (-0.56%)
Mutual labels:  graphql
Wp Graphql Jwt Authentication
Authentication for WPGraphQL using JWT (JSON Web Tokens)
Stars: ✭ 172 (-3.91%)
Mutual labels:  graphql
Storefront Api
Storefront GraphQL API Gateway. Modular architecture. ElasticSearch included. Works great with Magento1, Magento2, Spree, OpenCart, Pimcore and custom backends
Stars: ✭ 180 (+0.56%)
Mutual labels:  graphql
Ran
⚡ RAN! React . GraphQL . Next.js Toolkit ⚡ - SEO-Ready, Production-Ready, SSR, Hot-Reload, CSS-in-JS, Caching, CLI commands and more...
Stars: ✭ 2,128 (+1088.83%)
Mutual labels:  graphql
Human Connection
Free and open-source social network for active citizenship.
Stars: ✭ 177 (-1.12%)
Mutual labels:  graphql
Intro To Graphql
[Course] Introduction to GraphQL
Stars: ✭ 175 (-2.23%)
Mutual labels:  graphql
Giraffql
Interactive GraphQL exploration tool built with React - still working on the website
Stars: ✭ 176 (-1.68%)
Mutual labels:  graphql
Felipefialho.com
😺 My personal website
Stars: ✭ 177 (-1.12%)
Mutual labels:  graphql
Modelizr
Generate GraphQL queries from models that can be mocked and normalized.
Stars: ✭ 175 (-2.23%)
Mutual labels:  graphql
Apollo Cache Redux
Redux cache for Apollo Client 2.0. This project is no longer maintained.
Stars: ✭ 179 (+0%)
Mutual labels:  graphql
Scalable React Typescript Boilerplate
⭐️ Scalable micro-framework featuring React and TypeScript
Stars: ✭ 174 (-2.79%)
Mutual labels:  graphql
Kreta
Modern project management solution
Stars: ✭ 177 (-1.12%)
Mutual labels:  graphql
Prisma Examples
🚀 Ready-to-run Prisma example projects
Stars: ✭ 3,017 (+1585.47%)
Mutual labels:  graphql
React Auth App Example
An app example with authentication using Create React App, React, React Router, Apollo, GraphQL, Redux and Redux Form.
Stars: ✭ 179 (+0%)
Mutual labels:  graphql
React Apollo Form
Build React forms based on GraphQL APIs.
Stars: ✭ 178 (-0.56%)
Mutual labels:  graphql

venia

Clojars Project

Build Status

A Clojure(Script) qraphql query client library. Generate valid graphql queries with Clojure data structures.

Usage

Venia is originally supposed to be used in Clojurescript apps, but can be used as well in Clojure, as the core is written in CLJC. The sole purpose of this library is graphql query string generation from Clojure data, so that strings concatenations and manipulations could be avoided when using grapqhl. It is up to developers to hook it up to frontend apps. However, at least some sort of re-frame-graphql-fx library is on a roadmap.

Simple query

The easiest way to start with venia, is simple's query generation.

(ns my.project
  (:require [venia.core :as v]))

(v/graphql-query {:venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]]})

=> "{employee(id:1,active:true){name,address,friends{name,email}}}"

Obviously, If we would like to fetch employees and projects within the same simple query, we would do it this way:

(v/graphql-query {:venia/queries [[:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]
                                  [:projects {:active true} [:customer :price]]]})

=> "{employee(active:true){name,address},project(active:true){customer,price}}"

Field arguments

In the example above, :employee and :projects fields have arguments {:id 1 :active true} and {:id 1 :active true} respectively.

We can add arguments to other fields easily by wrapping field name and its arguments to vector [:customer {:id 2}]:

(v/graphql-query {:venia/queries [[:projects {:active true} [[:customer {:id 2}] :price]]]})

=> "{project(active:true){customer(id:2),price}}"

Query with alias

Now, if we need to have an alias for query, it can be easily achieved by using venia's query-with-data map

(v/graphql-query {:venia/queries [{:query/data [:employee {:id 1 :active true} [:name :address [:friends [:name :email]]]]
                                   :query/alias :workhorse}
                                  {:query/data  [:employee {:id 2 :active true} [:name :address [:friends [:name :email]]]]
                                   :query/alias :boss}]})
     
=> prettified:
{
  workhorse: employee(id: 1, active: true) {
    name
    address
  },
  boss: employee(id: 2, active: true) {
    name
    address
  }
}

In the query above, we use :query/data key for query definition and :query/alias for query's alias definition.

Query with fragments

What about fragments? Just add :venia/fragments vector with fragments definitions

(v/graphql-query {:venia/queries   [{:query/data  [:employee {:id 1 :active true} :fragment/comparisonFields]
                                     :query/alias :workhorse}
                                    {:query/data  [:employee {:id 2 :active true} :fragment/comparisonFields]
                                     :query/alias :boss}]
                  :venia/fragments [{:fragment/name   "comparisonFields"
                                     :fragment/type   :Worker
                                     :fragment/fields [:name :address]}]})

=> prettified:
{
  workhorse: employee(id: 1, active: true) {
    ...comparisonFields
  }
  boss: employee(id: 2, active: true) {
    ...comparisonFields
  }
}

fragment comparisonFields on Worker {
  name
  address
}

Query with variables

Now you can generate really complex queries with variables as well. In order to define variables, we need to define an operation type and name.

(v/graphql-query {:venia/operation {:operation/type :query
                                    :operation/name "employeeQuery"}
                  :venia/variables [{:variable/name    "id"
                                     :variable/type    :Int
                                     :variable/default 1}
                                    {:variable/name "name"
                                     :variable/type :String}]
                  :venia/queries   [{:query/data  [:employee {:id     :$id
                                                              :active true
                                                              :name   :$name}
                                                   :fragment/comparisonFields]
                                     :query/alias :workhorse}
                                    {:query/data  [:employee {:id     :$id
                                                              :active false}
                                                   :fragment/comparisonFields]
                                     :query/alias :boss}]
                  :venia/fragments [{:fragment/name   "comparisonFields"
                                     :fragment/type   :Worker
                                     :fragment/fields [:name :address [:friends [:name :email]]]}]})

=> prettified:
query employeeQuery($id: Int = 1, $name: String) {
  workhorse: employee(id: $id, active: true, name: $name) {
    ...comparisonFields
  }
  boss: employee(id: $id, active: false) {
    ...comparisonFields
  }
}

fragment comparisonFields on Worker {
  name
  address
  friends {
    name
    email
  }
}

Mutation

Mutations are also supported, just use :mutation operation type:


(v/graphql-query {:venia/operation {:operation/type :mutation
                                    :operation/name "AddProjectToEmployee"}
                  :venia/variables [{:variable/name "id"
                                     :variable/type :Int!}
                                    {:variable/name "project"
                                     :variable/type :ProjectNameInput!}]
                  :venia/queries   [[:addProject {:employeeId :$id
                                                  :project    :$project}
                                     [:allocation :name]]]})
                                     
=> prettified:
mutation AddProjectToEmployee($id:Int!,$project:ProjectNameInput!) {
  addProject(employeeId:$id, project:$project) {
    allocation,
    name
  }
}

Validation

Venia will verify that you don't use undefined variables or fragments.

For example, the following v/graphql-query calls will throw exceptions:


(v/graphql-query {:venia/queries [[:employee {:id 1 :active true} :fragment/undefined]]}

(v/graphql-query {:venia/queries [[:employee {:id 1 :active :$undefined} [:name]]]}))

because fragment and variable are never defined.

Meta fields

You can use graphql's __typename meta field anywhere inside of your query. For example:

(v/graphql-query {:venia/queries [[:employee [:meta/typename :name :address]]}

=> prettified:

{
  employee {
    __typename,
    name,
    address
  }
}

License

Copyright © 2017 Vincit

Distributed under the Eclipse Public License, the same as Clojure.

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