GithubHelp home page GithubHelp logo

rubensworks / solid-react-graphql-ld.js Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 0.0 375 KB

♻️ React components and hooks for building Solid apps with GraphQL-LD

License: MIT License

TypeScript 100.00%
solid react graphql-ld react-hooks react-components hacktoberfest

solid-react-graphql-ld.js's Introduction

Solid React GraphQL-LD

Build Status Coverage Status npm version

React components and hooks for building Solid apps with GraphQL-LD, a developer-friendly way to query Linked Data using GraphQL queries.

This package is fully compatible with the React Components for Solid, which means that GraphQL-LD queries will be able to query private resources when you are logged in with Solid.

More details on what kinds of queries you can write can be found in the README of the GraphQL-to-SPARQL repository.

This package makes use of the Comunica query engine using the GraphQL-LD Comunica Solid wrapper.

Installation

$ yarn add solid-react-graphql-ld

or

$ npm install solid-react-graphql-ld

Require

Import any of the available components and hooks

import { GraphQlLdProvider, Query, useQuery } from 'solid-react-graphql-ld';

Usage

Query component

Using the GraphQlLdProvider and Query components, you can execute queries and render its results within a custom UI.

The GraphQlLdProvider component will create a reusable query engine that is available for consumption by one or more Query components.

The Query component uses the internal query engine to execute a query, and render the results.

Example:

import gql from "graphql-tag";

<GraphQlLdProvider sources={[ 'https://www.rubensworks.net/' ]}>
  <Query
    query={gql`query @single(scope: all) {
      name
      image
      friends @plural {
        id
      }
    }`}
  >
    {({ loading, error, data }) => {
      if (loading) return <p>Loading...</p>;
      if (error) return <p>Error :(</p>;
      return (
        <dl>
          <dt>Full name</dt>
          <dd>{data.name}</dd>
          <dt>Image</dt>
          <dd><img src={data.image} alt={data.name} width="100px" /></dd>
          <dt>Friends</dt>
          <dd>
            <ul>
              {
                data.friends && data.friends.map(friend =>
                  <li key={friend.id}>{friend.id}</li>)
              }
            </ul>
          </dd>
        </dl>
      );
    }}
  </Query>
</GraphQlLdProvider>

GraphQlLdProvider props:

Either client and children, or sources and children are required.

Field Type Description
children (result: QueryResult) => React.ReactNode A function returning the UI you want to render based on your query result. (Required)
client QueryEngine A GraphQL-LD query engine. (Either this or sources is required.)
sources string[] An array of URLs to query from. (Either this or client is required.)
context `object string
baseIri baseIri The baseIRI using which the query will be parsed and resolved. (Only used with sources)

Query props:

Only query and children are required.

Field Type Description
children (result: QueryResult) => React.ReactNode A function returning the UI you want to render based on your query result. (Required)
query `string DocumentNode`
variables { [key: string]: any } An object containing all of the variables your query needs to execute.
queryEngineOptions any Optional query engine options to pass to the internal query engine.

Query hook

With the useQuery hook, you can create your own React components. Have a look at the implementation of the Query component on how this hook can be used.

Example

export function MyComponent() {
  // Only the query prop is required
  const result = useQuery({ query: '{ name @single }', variables: {}, queryEngineOptions: {} });
  return <span>My name is is {result.data.name}.</span>;
}

License

This software is written by Ruben Taelman.

This code is released under the MIT license.

solid-react-graphql-ld.js's People

Contributors

greenkeeper[bot] avatar renovate-bot avatar renovate[bot] avatar rubensworks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

solid-react-graphql-ld.js's Issues

An in-range update of @types/react is breaking the build 🚨

The dependency @types/react was updated from 16.9.2 to 16.9.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/react is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @types/n3 is breaking the build 🚨

The devDependency @types/n3 was updated from 1.1.3 to 1.1.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/n3 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @types/react is breaking the build 🚨

The dependency @types/react was updated from 16.9.7 to 16.9.8.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/react is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @solid/context ^1.1.0
  • @solid/react ^1.9.0
  • @types/jest ^26.0.0
  • @types/n3 ^1.1.4
  • @types/rdf-js ^3.0.0
  • graphql-ld ^1.1.0
  • graphql-ld-comunica-solid ^1.0.1
  • prop-types ^15.7.2
  • ts-invariant ^0.10.0
  • @testing-library/react ^13.0.0
  • @testing-library/react-hooks ^8.0.0
  • coveralls ^3.0.0
  • jest ^26.0.0
  • jest-mock-promise ^2.0.0
  • jest-rdf ^1.3.0
  • manual-git-changelog ^1.0.1
  • n3 ^1.0.0
  • pre-commit ^1.2.2
  • react ^18.0.0
  • react-dom ^18.0.0
  • react-test-renderer ^18.0.0
  • ts-jest ^26.0.0
  • tslint ^6.0.0
  • tslint-eslint-rules ^5.3.1
  • typescript ^4.0.0
  • react ^16.9.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.