graffle
Simple GraphQL Client for JavaScript. Minimal. Extensible. Type Safe. Runs everywhere.
Top Related Projects
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Open-source JavaScript charting library behind Plotly and Dash
Graph theory (network) library for visualisation and analysis
Directed graph layout for JavaScript
:dizzy: Display dynamic, automatically organised, customizable network views.
Quick Overview
Graffle is a JavaScript library for creating interactive and customizable graphs and charts. It provides a flexible API for building various types of visualizations, including line charts, bar charts, scatter plots, and more. Graffle aims to simplify the process of creating data visualizations for web applications.
Pros
- Highly customizable with a wide range of options for styling and interactivity
- Supports multiple chart types and can be extended with custom chart implementations
- Lightweight and performant, suitable for both small and large datasets
- Responsive design, adapting to different screen sizes and devices
Cons
- Limited documentation and examples compared to more established charting libraries
- Smaller community and ecosystem compared to popular alternatives like D3.js or Chart.js
- May require more setup and configuration for complex visualizations
- Limited built-in animations and transitions
Code Examples
Creating a simple line chart:
const data = [
{ x: 1, y: 10 },
{ x: 2, y: 15 },
{ x: 3, y: 13 },
{ x: 4, y: 17 }
];
const chart = new Graffle.LineChart('#chart-container', {
data: data,
xAxis: { label: 'X Axis' },
yAxis: { label: 'Y Axis' }
});
chart.render();
Customizing a bar chart with colors and tooltips:
const barChart = new Graffle.BarChart('#bar-chart', {
data: salesData,
colors: ['#3366cc', '#dc3912', '#ff9900'],
tooltip: {
formatter: (d) => `Sales: $${d.value}`
}
});
barChart.render();
Creating an interactive scatter plot:
const scatterPlot = new Graffle.ScatterPlot('#scatter-container', {
data: populationData,
xAxis: { label: 'Population' },
yAxis: { label: 'GDP' },
pointSize: 5,
onPointClick: (point) => {
console.log(`Clicked point: ${point.x}, ${point.y}`);
}
});
scatterPlot.render();
Getting Started
To use Graffle in your project, follow these steps:
-
Install Graffle via npm:
npm install graffle
-
Import Graffle in your JavaScript file:
import { LineChart } from 'graffle';
-
Create a container element in your HTML:
<div id="chart-container"></div>
-
Initialize and render a chart:
const chart = new LineChart('#chart-container', { data: yourData, // Add other configuration options here }); chart.render();
For more advanced usage and configuration options, refer to the Graffle documentation.
Competitor Comparisons
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of D3
- Extensive and powerful library with a wide range of visualization capabilities
- Large community and ecosystem with numerous examples and resources
- Fine-grained control over every aspect of data visualization
Cons of D3
- Steeper learning curve due to its low-level nature and complexity
- Requires more code to create basic visualizations compared to higher-level libraries
- Performance can be an issue with large datasets or complex visualizations
Code Comparison
D3:
const svg = d3.select("body").append("svg")
.attr("width", 400)
.attr("height", 300);
svg.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", 5);
Graffle:
const chart = new Graffle.Chart({
element: "#chart",
width: 400,
height: 300
});
chart.scatter(data, {
x: "x",
y: "y"
});
D3 offers more flexibility but requires more code, while Graffle provides a higher-level API for quicker implementation of common chart types. D3 is better suited for custom, complex visualizations, whereas Graffle is more appropriate for rapid development of standard charts with less customization.
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Pros of Mermaid
- More mature and widely adopted project with a larger community
- Supports a broader range of diagram types (e.g., flowcharts, sequence diagrams, Gantt charts)
- Better documentation and examples available
Cons of Mermaid
- Steeper learning curve due to its more complex syntax
- Limited customization options for diagram styling
- Larger file size and potentially slower rendering for complex diagrams
Code Comparison
Mermaid:
graph TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[End]
Graffle:
digraph {
A [label="Start"]
B [label="Is it?", shape=diamond]
C [label="OK"]
D [label="End"]
A -> B
B -> C [label="Yes"]
B -> D [label="No"]
}
Both libraries aim to create diagrams using text-based descriptions, but Mermaid uses a custom syntax while Graffle follows the DOT language. Mermaid's syntax is more concise and easier to read for simple diagrams, while Graffle's DOT-based approach offers more flexibility for complex graph structures.
Open-source JavaScript charting library behind Plotly and Dash
Pros of Plotly.js
- More comprehensive and feature-rich library with a wide range of chart types
- Extensive documentation and community support
- Interactive and customizable charts with built-in animations
Cons of Plotly.js
- Larger file size and potentially slower load times
- Steeper learning curve due to its extensive API
- May be overkill for simple visualization needs
Code Comparison
Plotly.js:
Plotly.newPlot('myDiv', [{
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
}]);
Graffle:
const chart = new Graffle.Chart();
chart.line([1, 2, 3, 4], [10, 15, 13, 17]);
chart.render('#myDiv');
Summary
Plotly.js offers a more comprehensive solution for data visualization with a wide range of chart types and interactive features. It has extensive documentation and community support, making it suitable for complex projects. However, its large file size and steep learning curve may be drawbacks for simpler use cases.
Graffle, on the other hand, appears to be a lighter-weight library with a simpler API, potentially making it easier to use for basic charting needs. It may be more suitable for projects that require quick implementation and smaller file sizes.
The choice between the two libraries depends on the specific requirements of your project, such as the complexity of visualizations needed, performance considerations, and development time constraints.
Graph theory (network) library for visualisation and analysis
Pros of Cytoscape.js
- More mature and widely adopted project with a larger community
- Extensive documentation and examples available
- Supports a wide range of graph visualization features and algorithms
Cons of Cytoscape.js
- Steeper learning curve due to its comprehensive feature set
- Larger file size, which may impact load times for simpler projects
- May be overkill for basic graph visualization needs
Code Comparison
Graffle:
const graph = new Graffle();
graph.addNode('A');
graph.addNode('B');
graph.addEdge('A', 'B');
graph.render('#container');
Cytoscape.js:
const cy = cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: 'A' } },
{ data: { id: 'B' } },
{ data: { source: 'A', target: 'B' } }
]
});
Both libraries allow for creating and rendering graphs, but Cytoscape.js offers more configuration options and a more complex API. Graffle aims for simplicity and ease of use, making it potentially more suitable for smaller projects or developers new to graph visualization. Cytoscape.js, on the other hand, provides a robust set of features for advanced graph manipulation and analysis, making it a better choice for complex graph-based applications.
Directed graph layout for JavaScript
Pros of dagre
- More mature and widely adopted project with a larger community
- Extensive documentation and examples available
- Supports a wider range of graph layout algorithms
Cons of dagre
- Last updated in 2018, potentially outdated
- Heavier and more complex, which may impact performance for simpler use cases
- Steeper learning curve due to its comprehensive feature set
Code Comparison
Graffle:
import { Graph } from 'graffle';
const graph = new Graph();
graph.addNode('A');
graph.addNode('B');
graph.addEdge('A', 'B');
dagre:
var g = new dagre.graphlib.Graph();
g.setNode("A", { label: "A" });
g.setNode("B", { label: "B" });
g.setEdge("A", "B");
Both libraries offer similar basic functionality for creating and manipulating graphs. Graffle's API appears slightly more concise, while dagre provides more options for node and edge attributes. The core concepts remain similar, making it relatively easy to switch between the two if needed.
:dizzy: Display dynamic, automatically organised, customizable network views.
Pros of vis-network
- More mature and widely adopted project with a larger community
- Extensive documentation and examples available
- Supports a wider range of graph visualization features and customization options
Cons of vis-network
- Larger file size and potentially heavier performance impact
- Steeper learning curve due to more complex API and configuration options
- Less focused on specific use cases, which may lead to unnecessary complexity for simpler projects
Code Comparison
vis-network:
var nodes = new vis.DataSet([
{ id: 1, label: 'Node 1' },
{ id: 2, label: 'Node 2' },
]);
var edges = new vis.DataSet([
{ from: 1, to: 2 },
]);
var container = document.getElementById('mynetwork');
var data = { nodes: nodes, edges: edges };
var options = {};
var network = new vis.Network(container, data, options);
graffle:
const graph = new Graffle();
graph.addNode('1', { label: 'Node 1' });
graph.addNode('2', { label: 'Node 2' });
graph.addEdge('1', '2');
graph.render('#mynetwork');
Both libraries allow for creating and rendering network graphs, but vis-network requires more setup code and offers more configuration options, while graffle provides a simpler API for basic graph creation and rendering.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
[!IMPORTANT] The next version (
8
) ofgraphql-request
is being renamed tograffle
. It has the same base simplicity but with many fixes, enhancements, and major new type safe features. It is not released yet but will be in the coming weeks/months and is already usable. Learn more about it here. You can see the in progress website at https://graffle.js.org.The following README is still for
graphql-request@7.x.x
graphql-request
Minimal GraphQL client supporting Node and browsers for scripts or simple apps.
Highlights
- Most simple & lightweight GraphQL client
- Promise-based API (works with
async
/await
) - Pure ESM package
- First class TypeScript support
- Including
TypedDocumentNode
- Including
- Isomorphic (works in both Node and Browsers)
Install
npm add graffle graphql
TypeScript Setup
This package uses package.exports
. Therefore if you are a TypeScript user you must:
- have your
tsconfig.json
moduleResolution
set to"bundler"
or"node16"
/"nodenext"
. - Have your
package.json
type
set to"module"
.
Quick Start
Send a GraphQL document using a static request function:
import { gql, request } from 'graffle'
const document = gql`
{
company {
ceo
}
}
`
await request('https://api.spacex.land/graphql/', document)
The function can be passed a configuration object for more complex cases:
await request({
url,
document,
variables,
requestHeaders,
})
A class is available for constructing your own instances:
import { gql, GraphQLClient } from 'graffle'
const document = gql`
{
company {
ceo
}
}
`
const endpoint = 'https://api.spacex.land/graphql/'
const client = new GraphQLClient(endpoint)
await client.request(document)
Examples
- Request:
- GraphQL:
- Configuration:
- TypeScript:
- Other:
Node Version Support
We only (officially) support versions of Nodejs of the following status:
- Current
- LTS
- Maintenance and end of life not yet reached
So for example on Oct 24 2023 that would mean these versions: 18, 20, 21.
Any issue that exists solely for an unsupported version of Nodejs will be rejected (not worked on).
Reference
â ï¸ This reference is incomplete. Check out the examples for more reference material.
Configuration
ErrorPolicy
By default GraphQLClient will throw when an error is received. However, sometimes you still want to resolve the (partial) data you received.
You can define errorPolicy
in the GraphQLClient
constructor.
const client = new GraphQLClient(endpoint, { errorPolicy: 'all' })
None (default)
Allow no errors at all. If you receive a GraphQL error the client will throw.
Ignore
Ignore incoming errors and resolve like no errors occurred
All
Return both the errors and data, only works with rawRequest
.
IgnoreOperationName
OperationName has been introduced to address issues reported here Support operation name, However, on certain occasions this information may not be needed in requests. In such cases, you might consider ignoring operationName to avoid the extraction steps currently performed by a parsing operation when the document is provided in string format.
By default the GraphQLClient tries to extract the operationName from the document.
You can define excludeOperationName
in the constructor of GraphQLClient to avoid the extraction process if it is not needed. This can be useful if you don't use operationName and want to optimise queries by reducing the amount of computation as much as possible, especially if we are in a context where we are using documents in string format to reduce bundle size.
// example where the operation name is not ignored
const client = new GraphQLClient(endpoint, {
method: 'POST',
})
// example in which the operation name is ignored
const client = new GraphQLClient(endpoint, {
method: 'POST',
excludeOperationName: true,
})
Knowledge Base
Why was the file upload feature taken away? Will it return?
In this issue we decided to make this library more stable and maintainable. In principal the feature is still in scope of this library and will make a return when we find time to do the feature right.
Why do I have to install graphql
?
graffle
uses methods exposed by the graphql
package to handle some internal logic. On top of that, for TypeScript users, some types are used from the graphql
package to provide better typings.
Do I need to wrap my GraphQL documents inside the gql
template exported by graffle
?
No. It is there for convenience so that you can get the tooling support like automatic formatting and syntax highlighting. You can use gql
from graphql-tag
if you need it for some reason too.
What sets graffle
apart from other clients like Apollo, Relay, etc.?
graffle
is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps.
Compared to GraphQL clients like Apollo or Relay, graffle
doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.
Project Stats
Package Installs

Repo Beats
Top Related Projects
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Open-source JavaScript charting library behind Plotly and Dash
Graph theory (network) library for visualisation and analysis
Directed graph layout for JavaScript
:dizzy: Display dynamic, automatically organised, customizable network views.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot