Skip to content

Commit f932524

Browse files
committed
Initial commit and scribbles
1 parent 003c3a4 commit f932524

File tree

21 files changed

+1466
-50
lines changed

21 files changed

+1466
-50
lines changed

packages/iiif-graphql/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/coverage
2+
/dist
3+
/node_modules
4+
npm-debug.log*

packages/iiif-graphql/CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Prerequisites
2+
3+
[Node.js](http://nodejs.org/) >= v4 must be installed.
4+
5+
## Installation
6+
7+
- Running `npm install` in the app's root directory will install everything you need for development.
8+
9+
## Development Server
10+
11+
- `npm start` will run the app's development server at [http://localhost:3000](http://localhost:3000) with hot module reloading.
12+
13+
## Running Tests
14+
15+
- `npm test` will run the tests once.
16+
17+
- `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`.
18+
19+
- `npm run test:watch` will run the tests on every change.
20+
21+
## Building
22+
23+
- `npm run build` creates a production build by default.
24+
25+
To create a development build, set the `NODE_ENV` environment variable to `development` while running this command.
26+
27+
- `npm run clean` will delete built resources.

packages/iiif-graphql/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# IIIF Graphql
2+
3+
IIIF specification through GraphQL over rest. Thats the goal, this is the start. It is a heavy client-side implementation built on top of IIIF Redux, which acts as safe-access and a unified API to both IIIF Presentation 2 and Presentation 3 resources.
4+
5+
The goal of this library will be to offer both a server implementation and client side implementation. The server implementation will have the option to be hooked up to a non-IIIF data source through a layer over the resolver API for institutions collections. It will also feature an out of the box proxy to content hosted in the IIIF space so you can host your own IIIF GraphQL instance that can query any IIIF content, composed together for building your own applications and tools.
6+
7+
The client implementation will get better with time, but the main focus is building a single implementation that can work both on the server and on the client.
8+
9+
## The why
10+
11+
At the moment the IIIF space is full of duplicate code, multiple solutions to the same problem and lots of already solved problems that are hard to discover. This implementation of GraphQL is intended to become a place to colabourate on solving common problems parsing IIIF data and building a library of GraphQL resolvers and custom queries that can be used quickly in small to large projects.
12+
13+
## The what
14+
15+
Heres the dream query:
16+
17+
```graphql
18+
query getManifest($id: String, $q: String!) {
19+
manifest(id: $id) {
20+
id
21+
label
22+
metadata {
23+
label
24+
value
25+
}
26+
search(query: $q) {
27+
results {
28+
canvasId
29+
contentAsText
30+
selector {
31+
x
32+
y
33+
width
34+
height
35+
}
36+
}
37+
}
38+
canvases {
39+
id
40+
label
41+
thumbnail: thumbnailAtSize(size: 200) {
42+
src
43+
height
44+
width
45+
}
46+
tiledImages {
47+
height
48+
width
49+
tiles
50+
scaleFactor
51+
}
52+
}
53+
}
54+
}
55+
```
56+
57+
If you are unfamiliar with GraphQL, the key concept is that they query language descibes a JSON format that you want returned. You can read this query and know what the fields will be and so can predicably start using these fields.
58+
59+
Reading through this query, you can see we are grabbing some basic properties like `id` and `label` from the manifest. We are also requesting the metadata pairs. This is always an array, so each item in the array will match the format `{label: "str", value: "str"}`. Translation is done automatically using a global context (to be documented).
60+
61+
The next section is where the power of GraphQL starts coming through, theres a search block that accepts `query` just like the IIIF specification. Behind the scenes this will be doing many things:
62+
63+
- Checking if the resource has a search service
64+
- Fetching the service
65+
- Constructing and executing the search
66+
- Formatting and parsing that back in your desired format
67+
68+
In addition, because this is using IIIF Redux under the hood, any references (such as targets) in the search results or any request are maintained as logical links. IIIF Redux maintains that graph and makes it query-able here.
69+
70+
The next section `canvases` is dropping deeper into the graph of the manifest. You can go as deep as you want or need to here. You can see another non-IIIF property in the query `thumbnailAtSize` being assigned to the `thumbnail` property. This is another theoretical extension where some derived data is being reduced into a handful of fields. Under the hood this could be:
71+
72+
- Finding a thumbnail service
73+
- Finding a thumbnail static image, checking its height/width against your requested height
74+
- Looking for an image service in the annotations
75+
76+
In the end its goal is to find the best thumbnail given the criteria. This is immediately available in the query language to be reused once created. It can be improved.
77+
78+
## The how
79+
80+
Slowly. This is the start of this project that I am working on in my down-time. Currently with IIIF Redux you can use functional composition to create a bunch of queries for IIIF content, but the interface to that is low-level but fail-safe. The goal of IIIF-GraphQL is to be both fail-safe and nice to work with.
81+
82+
GraphQL and apollo, the library that this is using, has integrations with every Frontend framework under the sun. There is no lock-in with this library, this broadens the developer interest and collabouration.
83+
84+
## Roadmap
85+
86+
The road map is not in any particular order. The first goal is a base for collabouration. The second goal is exploring some of the challenges in IIIF-space using GraphQL.
87+
88+
### v1.0
89+
90+
- Fully IIIF compliant GraphQL type definition
91+
- Full compatibility with Presentation 2 over a presentation 3 query interface
92+
- Extension model to start adding derived fields to queries
93+
- v1.0 IIIF explorer using GraphQL
94+
- Cookbook of GraphQL queries for common UI interfaces
95+
96+
### v1.x
97+
98+
- W3C Annotation compliant GraphQL type definition
99+
- IIIF Image 2.x compliant GraphQL type definition
100+
- IIIF Activity stream compliant GraphQL type definition
101+
- IIIF Discovery integration in GraphQL server (invalidating caches)
102+
- IIIF Authentication compliant GraphQL type defintion
103+
- Authentication extensions

packages/iiif-graphql/nwb.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
type: 'react-app',
3+
};

packages/iiif-graphql/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "iiif-graphql",
3+
"version": "1.0.0",
4+
"description": "Describe iiif-graphql here",
5+
"private": true,
6+
"scripts": {
7+
"build": "nwb build-react-app",
8+
"clean": "nwb clean-app",
9+
"start": "nwb serve-react-app",
10+
"test": "echo \"No tests yet\""
11+
},
12+
"dependencies": {
13+
"iiif-redux": "1.0.0",
14+
"apollo-cache-inmemory": "^1.3.5",
15+
"apollo-client": "^2.4.2",
16+
"apollo-link": "^1.2.3",
17+
"apollo-link-schema": "^1.1.1",
18+
"apollo-link-set-context": "^0.5.4",
19+
"graphql": "^14.0.2",
20+
"graphql-tag": "^2.10.0",
21+
"graphql-tools": "^4.0.1",
22+
"react": "^16.5.2",
23+
"react-apollo": "^2.2.4",
24+
"react-dom": "^16.5.2"
25+
},
26+
"devDependencies": {
27+
"nwb": "0.19.x"
28+
},
29+
"author": "",
30+
"license": "MIT",
31+
"repository": ""
32+
}

packages/iiif-graphql/public/.gitkeep

Whitespace-only changes.

packages/iiif-graphql/src/App.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.App {
2+
height: 100%;
3+
min-height: 400px;
4+
text-align: center;
5+
display: flex;
6+
flex-direction: column;
7+
justify-content: stretch;
8+
}
9+
10+
.App-flex {
11+
flex: 1;
12+
display: flex;
13+
align-items: center;
14+
justify-content: center;
15+
}
16+
17+
.App-heading {
18+
background-color: #222;
19+
color: #f8f8f8;
20+
font-size: 6vh;
21+
box-shadow: 0px 4px 4vh 4px rgba(34,34,34,0.9);
22+
z-index: 2;
23+
}
24+
25+
.App-react {
26+
color: #00d8ff;
27+
text-decoration: overline underline;
28+
}
29+
30+
.App-logo {
31+
max-height: 30vh;
32+
max-width: 30vh;
33+
}
34+
35+
.App-instructions {
36+
background-color: #f8f8f8;
37+
color: #222;
38+
font-size: 3vh;
39+
line-height: 1.5;
40+
padding: 0 1em;
41+
}
42+
43+
.App-instructions code {
44+
background-color: #222;
45+
color: #00d8ff;
46+
padding: .2em .3em;
47+
border-radius: .2em;
48+
}

packages/iiif-graphql/src/App.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import './App.css';
2+
3+
import React, { Component } from 'react';
4+
import { ApolloProvider } from 'react-apollo';
5+
import HelloWorld from './components/HelloWorld';
6+
7+
import client from './graphql/client';
8+
9+
class App extends Component {
10+
state = {
11+
client: null,
12+
};
13+
14+
async componentWillMount() {
15+
this.setState({ client: await client });
16+
}
17+
18+
render() {
19+
if (!this.state.client) {
20+
return 'Loading ...';
21+
}
22+
return (
23+
<ApolloProvider client={this.state.client}>
24+
<HelloWorld />
25+
</ApolloProvider>
26+
);
27+
}
28+
}
29+
30+
export default App;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, { Component } from 'react';
2+
import { Query } from 'react-apollo';
3+
import gql from 'graphql-tag';
4+
5+
const queryText = gql`
6+
query {
7+
getCollection(
8+
collectionId: "https://view.nls.uk/collections/7446/74466699.json"
9+
) {
10+
id
11+
type
12+
label
13+
metadata {
14+
label
15+
value
16+
}
17+
}
18+
getManifest(
19+
manifestId: "https://wellcomelibrary.org/iiif/b20432033/manifest"
20+
) {
21+
id
22+
type
23+
label
24+
metadata {
25+
label
26+
value
27+
}
28+
}
29+
getTest {
30+
label
31+
}
32+
}
33+
`;
34+
35+
class HelloWorld extends Component {
36+
render() {
37+
return (
38+
<Query query={queryText}>
39+
{({ data, loading, error }) => {
40+
if (loading) {
41+
return <h2> Loading </h2>;
42+
}
43+
if (error) {
44+
return <h2> {JSON.stringify(error)} </h2>;
45+
}
46+
47+
return <pre>{JSON.stringify(data, null, 2)}</pre>;
48+
}}
49+
</Query>
50+
);
51+
}
52+
}
53+
54+
export default HelloWorld;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { SchemaLink } from 'apollo-link-schema';
2+
import { InMemoryCache } from 'apollo-cache-inmemory';
3+
import SetContextLink from 'apollo-link-set-context';
4+
import { ApolloLink } from 'apollo-link';
5+
import { createStore } from 'iiif-redux';
6+
import ApolloClient from 'apollo-client';
7+
import schema from './schema';
8+
9+
const store = createStore();
10+
11+
// const link = ApolloLink.from([
12+
// consoleLink,
13+
// TestLink,
14+
// new SchemaLink({ schema, context: { store } }),
15+
// ]);
16+
17+
const client = new ApolloClient({
18+
link: new SchemaLink({ schema, context: { store } }),
19+
cache: new InMemoryCache(),
20+
});
21+
22+
export default client;

0 commit comments

Comments
 (0)