• Stars
    star
    617
  • Rank 72,724 (Top 2 %)
  • Language
    Clojure
  • License
    MIT License
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pathom is a Clojure(script) engine for processing EQL requests.

pathom Clojars Project Test cljdoc badge

A Clojure library designed to help you write Clojure(script) graph query processing parsers for the query notation used by EQL.

For an introduction to general parser development please check my article on the subject. This library encapsulates the ideas presented there. And all documentation here assumes you understand the Om.next query syntax.

Pathom 3

Hello, if you are new here, I suggest you have a look at Pathom 3!

Pathom 3 still in alpha, but it's the library that will get updated ahead, and most of the API is already stable, Pathom 2 (current here) is only updating in case of bug fixes.

Usage

The library has a number of different usage models. One of the most commonly used features is Connect. The basic idea is as follows:

  • You define resolvers that can take simple inputs (e.g. entity ID) and turn that into a set of outputs.
  • Your resolvers implies "edges" by outputting IDs that can be further resolved by other resolvers.

The Connect features support advanced features for being able to then traverse this graph via queries in useful ways.

For example, here is how you might generate the support for queries about people and their addresses.

While reading this, note that the join implied from person to address is an artifact of the resolver, not the database (and thus is independent of the schema of the real database):

(ns sample-query-processing
  (:require
    [com.wsscode.pathom.core :as p]
    [com.wsscode.pathom.connect :as pc]
    [clojure.core.async :refer [<!!]]))

;; How to go from :person/id to that person's details
(pc/defresolver person-resolver [env {:keys [person/id] :as params}]
  ;; The minimum data we must already know in order to resolve the outputs
  {::pc/input  #{:person/id}
   ;; A query template for what this resolver outputs
   ::pc/output [:person/name {:person/address [:address/id]}]}
  ;; normally you'd pull the person from the db, and satisfy the listed
  ;; outputs. For demo, we just always return the same person details.
  {:person/name "Tom"
   :person/address {:address/id 1}})
     
;; how to go from :address/id to address details.
(pc/defresolver address-resolver [env {:keys [address/id] :as params}]
  {::pc/input  #{:address/id}
   ::pc/output [:address/city :address/state]}
  {:address/city "Salem"
   :address/state "MA"})

;; define a list with our resolvers
(def my-resolvers [person-resolver address-resolver])

;; setup for a given connect system
(def parser
  (p/parser
    {::p/env     {::p/reader               [p/map-reader
                                            pc/reader2
                                            pc/open-ident-reader
                                            p/env-placeholder-reader]
                  ::p/placeholder-prefixes #{">"}}
     ::p/mutate  pc/mutate
     ::p/plugins [(pc/connect-plugin {::pc/register my-resolvers})
                  p/error-handler-plugin
                  p/trace-plugin]}))

;; A join on a lookup ref (Fulcro ident) supplies the starting state of :person/id 1.
;; env can have anything you want in it (e.g. a Datomic/SQL connection, network service endpoint, etc.)
;; the concurrency is handled though core.async, so you have to read the channel to get the output
(parser {} [{[:person/id 1] [:person/name {:person/address [:address/city]}]}])
; => {[:person/id 1] {:person/name "Tom" :person/address {:address/city "Salem"}}}

In the example above hopefully you can start to see the general power: Small resolvers that can find specific details based on known information, can generate "graph edges" on the fly, and can be arbitrarily connected by Pathom. Any given input can have any number of resolvers, meaning that composition over time is trivial.

For example, say you wanted to add a resolver that could go from :person/id to their purchase history. No need to add that to an existing resolver, you can simply add a new one that lists the new outputs!

(defresolver `person-resolver
  {::pc/input  #{:person/id}
   ::pc/output [{:person/recent-purchases [:purchase/id]}]}
  ...)

note also that this resolver only needs to do the work of resolving the (to-many) edge. Another resolver (for purchase) can take care of the actual purchase details. This makes the resolvers reusable! There's never a need to write the resolver for purchase details more than once, since other resolvers can be defined to generate the edges from source entities (e.g. customers, b2b transactions, etc.) to their minimal representation (e.g. ID) which can then be further processed by other specialized resolvers.

Another thing to point out, these factory functions we build at the boilerplate are intended to be used across many files, so as your resolver library grows you can split it up.

See a Talks on the Concepts

The power possible with Clojure's concepts of fully-namespaced keys and flexible data schema lead to a number of interesting and useful results. I explore these ideas in some talks:

Documentation

Read the documentation at https://wilkerlucio.github.io/pathom/v2

Building the docs

In case you like to contribute to docs, you need to first install Antora.

Then you can build the changes locally running:

antora docs-dev.yml

Visualization Tools

Pathom provides a set of visualization tools, including a codemirror mode with support to auto-complete, a tracer timeline visualization to track queries and more, you can find these modules at Pathom Viz.

Support

If you have any questions, check the #pathom channel on Clojurians.

More Repositories

1

pathom3

A library for navigating data.
Clojure
369
star
2

spec-coerce

Coerce by leveraging your specs
Clojure
206
star
3

mongoid_taggable

Mongoid taggable behaviour
Ruby
196
star
4

pathom-viz

Visualization tools for Pathom
Clojure
87
star
5

wsscode-async

Core.async utilities package.
Clojure
78
star
6

edn-json

Tools to convert back and forth between EDN and JSON, optimised for storage and JSON tooling friendliness.
Clojure
63
star
7

huffman_js

Huffman Algorithm in Javascript
JavaScript
57
star
8

tailwind-garden

Port of Tailwind CSS library to Garden format in Clojure
Clojure
56
star
9

lein-node-webkit-build

Build node-webkit applications with Leiningen
Clojure
51
star
10

pathom-datomic

Pathom Connect integration with Datomic
Clojure
39
star
11

js-data-interop

Clojurescript <-> JS data interop using specialized data structures.
Clojure
22
star
12

jcheck_rails

wilkerlucio
Ruby
21
star
13

jquery-autoscroll

Creates one automatic scroll system that moves with user mouse movements
JavaScript
21
star
14

jcheck

Javascript validations done right
JavaScript
19
star
15

pathom3-graphql

GraphQL Integration for Pathom 3
Clojure
18
star
16

jquery-multiselect

jQuery multiselect implementation
JavaScript
18
star
17

oge

Om Graph Explorer
Clojure
17
star
18

transito

Helpers for common Clojure transit operations
Clojure
17
star
19

subdb

Ruby client and API for SubDB download and upload
Ruby
16
star
20

pathom3-docs

Documentation and blog site for Pathom 3
Clojure
16
star
21

media-looper

Clojure
14
star
22

bow_and_arrow

The old bow and arrow windows game recreated with Ruby and Shoes
Ruby
12
star
23

aidmock

Safe mocking
Ruby
12
star
24

pathom-viz-connector

Clojure
11
star
25

dragonfly_mongoid_extensions

Add support for Mongoid in Dragonfly
Ruby
10
star
26

presentation-data-navigation-with-pathom3

Sources of demo for the presentation: Data Navigation with Pathom 3
Clojure
10
star
27

pathom-connect-youtube

Clojure
9
star
28

conj2018demo

Code used in Scaling Full Stack Applications presentation
Clojure
9
star
29

pathom3-datomic

Clojure
8
star
30

ember-youtube-manager

Ember demo implementing Youtube new interface for video manager.
JavaScript
8
star
31

multi-timer

Clojure
7
star
32

mazes

My studies on the Mazes for Programmers book
Clojure
7
star
33

youtube-gmail-queue-plugin

Clojure
7
star
34

barrier

A test framework that embraces promises for real
JavaScript
7
star
35

patterny

Automatically extract minimum pattern of an image
Clojure
7
star
36

limber

Limber PHP MVC Framework
PHP
6
star
37

clojure-days-clojure-graph-presentation

Clojure
6
star
38

om-cookbook

Receipt tutorials for Om library.
Clojure
6
star
39

pathom-connect-spacex

Clojure
6
star
40

cljc-misc

Clojure
6
star
41

calendar_iterator

Calendar Iterator is a simple API to iterate of a calendar days of a month
Ruby
5
star
42

dart-stylus

Dart
5
star
43

chunked-transfer

Stream transfer of clojure data structures
Clojure
5
star
44

pathom-book

Documentation for Pathom
5
star
45

limber-haml

PHP Implementation of Haml
PHP
5
star
46

pathom3-integrant

Clojure
5
star
47

cocoa_simple_multipart

Objective-C
4
star
48

pencil-draw

Pencil draw experiment
JavaScript
4
star
49

scripted_css

Make your CSS's more powerful than ever!
CoffeeScript
4
star
50

fishy-framework

Prototype of php web framework
PHP
3
star
51

promesa-bridges

Clojure
3
star
52

limber-spec

PHP BDD Library created for Limber Framework
PHP
3
star
53

future_goodies

Future goodies for Dart
Dart
3
star
54

fulcro-graphql

Clojure
3
star
55

collabsubtitles-extension

Clojure
3
star
56

dotfiles

My dotfiles
Vim Script
3
star
57

jena-clj

Clojure
3
star
58

fuzzy-cljs

JavaScript
2
star
59

pathom3-viz

Clojure
2
star
60

pathom3-demo-gcf

Clojure
2
star
61

spotify-pathom

Source code for tutorial on pathom spotify
Clojure
2
star
62

pathom-connect-ynab

Clojure
2
star
63

pathom-cljs-demo

Simple repository with a demo setup for Pathom in CLJS with Shadow
Clojure
2
star
64

fishy-framework-bundles

Textmate Bundles for Fishy Framework
1
star
65

wilker-tmbundles

My Custom general bundles
1
star
66

spec-inspec

Helpers to navigate Clojure specs.
Clojure
1
star
67

cljs-compilation-fail

Clojure
1
star
68

alfred_ex_chrome_bookmarks

Elixir
1
star
69

match-comb-shadow-repro

Clojure
1
star
70

fishy-framework-base

Basic directory structure for using with Fishy Framework
PHP
1
star
71

remember-mobile

Clojure
1
star
72

ws.squares

WebSockets experiment with Node
JavaScript
1
star
73

d3-in-action-storybook

HTML
1
star
74

simplehttp

Simple HTTP import from rubyforge
Ruby
1
star
75

mower

Clojure
1
star
76

staticfy

Ruby
1
star
77

inject-it

Simple Javascript injector
CoffeeScript
1
star
78

subdb-sync

SubDB GUI
Ruby
1
star
79

todomvc-cljs

HTML
1
star
80

wilkerlucio.github.com

HTML
1
star
81

clj-subdb

Clojure SubDB API
Clojure
1
star
82

icontact

modified copy of nate63179-icontact
Ruby
1
star
83

rabbit-forms

CRUD related library for CodeIgniter
1
star
84

html-om

HTML to Om converter
JavaScript
1
star
85

absin

A crazy programming language
CoffeeScript
1
star
86

cooktimer

Clojure
1
star