All Projects → rubensworks → Graphql Ld.js

rubensworks / Graphql Ld.js

Licence: mit
Linked Data Querying with GraphQL

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Graphql Ld.js

Rdf4j
Eclipse RDF4J: scalable RDF for Java
Stars: ✭ 242 (+272.31%)
Mutual labels:  hacktoberfest, linked-data, sparql
Comunica
📬 A knowledge graph querying framework for JavaScript
Stars: ✭ 183 (+181.54%)
Mutual labels:  graphql, hacktoberfest, sparql
Hypergraphql
GraphQL interface for querying and serving linked data on the Web.
Stars: ✭ 112 (+72.31%)
Mutual labels:  graphql, linked-data, sparql
Semanticmediawiki
🔗 Semantic MediaWiki turns MediaWiki into a knowledge management platform with query and export capabilities
Stars: ✭ 359 (+452.31%)
Mutual labels:  linked-data, query, sparql
Hypergraphql
GraphQL interface for querying and serving linked data on the Web.
Stars: ✭ 120 (+84.62%)
Mutual labels:  graphql, linked-data, sparql
Graphql To Sparql.js
Converts GraphQL queries to SPARQL queries
Stars: ✭ 62 (-4.62%)
Mutual labels:  graphql, hacktoberfest, sparql
Stash
An organizer for your porn, written in Go
Stars: ✭ 591 (+809.23%)
Mutual labels:  graphql, hacktoberfest
Testing Nestjs
A repository to show off to the community methods of testing NestJS including Unit Tests, Integration Tests, E2E Tests, pipes, filters, interceptors, GraphQL, Mongo, TypeORM, and more!
Stars: ✭ 685 (+953.85%)
Mutual labels:  graphql, hacktoberfest
Mercurius
Implement GraphQL servers and gateways with Fastify
Stars: ✭ 704 (+983.08%)
Mutual labels:  graphql, hacktoberfest
Strawberry
A new GraphQL library for Python 🍓
Stars: ✭ 891 (+1270.77%)
Mutual labels:  graphql, hacktoberfest
Graphqlmap
GraphQLmap is a scripting engine to interact with a graphql endpoint for pentesting purposes.
Stars: ✭ 434 (+567.69%)
Mutual labels:  graphql, hacktoberfest
Elide
Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.
Stars: ✭ 766 (+1078.46%)
Mutual labels:  graphql, hacktoberfest
Sql To Graphql Schema Generator
⚛️ Generate GraphQL Scheme Online From SQL Query - https://sql-to-graphql.now.sh/
Stars: ✭ 32 (-50.77%)
Mutual labels:  graphql, hacktoberfest
Learn Graphql
Real world GraphQL tutorials for frontend developers with deadlines!
Stars: ✭ 586 (+801.54%)
Mutual labels:  graphql, hacktoberfest
Cookiecutter Django Vue
Cookiecutter Django Vue is a template for Django-Vue projects.
Stars: ✭ 462 (+610.77%)
Mutual labels:  graphql, hacktoberfest
Offix
GraphQL Offline Client and Server
Stars: ✭ 694 (+967.69%)
Mutual labels:  graphql, hacktoberfest
Graphql Engine
Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
Stars: ✭ 24,845 (+38123.08%)
Mutual labels:  graphql, hacktoberfest
Schemathesis
A modern API testing tool for web applications built with Open API and GraphQL specifications.
Stars: ✭ 768 (+1081.54%)
Mutual labels:  graphql, hacktoberfest
Laravel Graphql
GraphQL implementation with power of Laravel
Stars: ✭ 56 (-13.85%)
Mutual labels:  graphql, query
Umbraco Graphql
An implementation of GraphQL for Umbraco 8 using GraphQL for .NET.
Stars: ✭ 52 (-20%)
Mutual labels:  graphql, hacktoberfest

GraphQL-LD

Build Status Coverage Status npm version

GraphQL-LD allows Linked Data to be queried via GraphQL queries and a JSON-LD context.

It is a developer-friendly way to query Linked Data and use the results in a straightforward way.

For example, assuming the following SPARQL query:

SELECT ?id ?starring WHERE {
  OPTIONAL {
    ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Film>;
      <http://dbpedia.org/ontology/starring> ?starring.
    ?starring <http://www.w3.org/2000/01/rdf-schema#label> "Brad Pitt"@en.
  }
}

This could be written in a more compact way in GraphQL:

{
  id
  ... on Film {
    starring(label: "Brad Pitt")
  }
}

And this can be based on the following JSON-LD context:

{
  "@context": {
    "Film": "http://dbpedia.org/ontology/Film",
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "starring": "http://dbpedia.org/ontology/starring"
  }
}

Approach

This library takes a GraphQL-LD query and a JSON-LD context as input, converts it to a SPARQL query, sends the SPARQL query to a SPARQL query engine for execution (local or endpoint), and converts the SPARQL query results into a tree-based structure corresponding to the original GraphQL query.

More information about this approach can be found in our GraphQL-LD article.

Install

$ yarn add graphql-ld

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Require

import {Client} from "graphql-ld";

or

var Client = require("graphql-ld").Client;

Usage

With a client-side query engine

This requires you to install graphql-ld-comunica: yarn add graphql-ld-comunica.

If you want to use this for Solid apps, have a look at graphql-ld-comunica-solid instead.

import {Client} from "graphql-ld";
import {QueryEngineComunica} from "graphql-ld-comunica";

// Define a JSON-LD context
const context = {
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" }
  }
};

// Create a GraphQL-LD client based on a client-side Comunica engine over 2 sources
const comunicaConfig = {
  sources: [ "http://dbpedia.org/sparql", "https://ruben.verborgh.org/profile/" ],
};
const client = new Client({ context, queryEngine: new QueryEngineComunica(comunicaConfig) });

// Define a query
const query = `
  query @single {
    label
  }`;

// Execute the query
const { data } = await client.query({ query });

With a remote SPARQL endpoint

This requires you to install graphql-ld-sparqlendpoint: yarn add graphql-ld-sparqlendpoint.

import {Client} from "graphql-ld";
import {QueryEngineSparqlEndpoint} from "graphql-ld-sparqlendpoint";

// Define a JSON-LD context
const context = {
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" }
  }
};

// Create a GraphQL-LD client based on a SPARQL endpoint
const endpoint = 'http://dbpedia.org/sparql';
const client = new Client({ context, queryEngine: new QueryEngineSparqlEndpoint(endpoint) });

// Define a query
const query = `
  query @single {
    label
  }`;

// Execute the query
const { data } = await client.query({ query });

Examples

Below, you can find a couple examples of GraphQL-LD queries.

If you want more details on what kind of queries you can write, have a look at the README of the GraphQL-to-SPARQL repository.

Finding all available labels

Query:

query @single {
  label
}

Context:

{
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" }
  }
}

Output:

{
  "data": {
    "label": [
      "amateur victory",
      "amateur year",
      "ambasadóir",
      "ambasciatore",
      "ambassadeur",
      "ambassadeur",
      "ambassador",
      ...
    ]
  }
}

Finding all movies Brad Pitt stars in

Query:

{
  id @single
  ... on Film {
    starring(label: "Brad Pitt") @single
  }
}

Context:

{
  "@context": {
    "Film": "http://dbpedia.org/ontology/Film",
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "starring": "http://dbpedia.org/ontology/starring"
  }
}

Output:

{
  "data": [
    {
      "id": "http://dbpedia.org/resource/Ocean's_Eleven",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/The_Favor",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/The_Assassination_of_Jesse_James_by_the_Coward_Robert_Ford",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/True_Romance",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    ...
  ]
}

Finding all Belgian software developers

Query:

{
  softwareName: label @single
  developer @single(scope: all) {
    label
    country(label_en: "Belgium")
  }
}

Context:

{
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" },
    "label_en": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "developer": { "@id": "http://dbpedia.org/ontology/developer" },
    "country": { "@id": "http://dbpedia.org/ontology/locationCountry" }
  }
}

Output:

{
  "data": [
    {
      "softwareName": "Divinity: Original Sin II",
      "developer": {
        "label": "Larian Studios",
        "country": "http://dbpedia.org/resource/Belgium"
      }
    },
    {
      "softwareName": "Divinity: Original Sin II",
      "developer": {
        "label": "Larian Studios",
        "country": "http://dbpedia.org/resource/Belgium"
      }
    },
    {
      "softwareName": "BioNumerics",
      "developer": {
        "label": "Applied Maths",
        "country": "http://dbpedia.org/resource/Belgium"
      }
    },
    ...
  ]
}

License

This software is written by Ruben Taelman.

This code is released under the MIT license.

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