Full Graphql React app

I followed this how-to https://www.stardog.com/tutorials/how-to-bulid-react-app-in-stardog/ which use a SparQL query. It says there is a way to make it work with a graphql query instead and that it'll be shown in a following blog post. I didn't find another post on it so I wonder if someone made it or can provide tips to make it work.
Thanks

@sirvente

1. javascript stardog client

2. graphql http endpoint

or you can use http endpoint like this
and the coolest thing is you don't have to write a graphql schema, you can query directly if you already have tripples in database

const graphqlQuery = (query) => axios.post(`http://localhost:5820/test/graphql`, { query }, {
  auth: {
    username: 'admin',
    password: 'admin',
  }
})

const { data: userFormResp } = await graphqlQuery(`
    {
      Form(id: "test") {
        name
        hasSection {
          name
          show @optional {
            when
            value
          }
          hide @optional
          hasInput {
            type
            name
            label
            hasOption @optional {
              value
              label
              checked @optional
            }
          }
        }
      }
    }
  `)

3. use json-ld

and you can use json-ld with SPARQL CONSTRUCT

something like this

  const resp = awaitQuery(`
    CONSTRUCT {
      ?concept :children ?narrowerConcept .
      ?concept :title ?conceptLabel.
      ?narrowerConcept :title ?narrowerConceptLabel .
    }
    WHERE {
      ?concept a skos:Concept ;
        skosxl:prefLabel/skosxl:literalForm ?conceptLabel .
        OPTIONAL {
          ?concept skos:narrower ?narrowerConcept .
          ?narrowerConcept skosxl:prefLabel/skosxl:literalForm ?narrowerConceptLabel .
        }
    }
  `, {
    database: 'app',
    reasoning: true,
    mimeType: 'application/ld+json',
  })

a stardog next.js starter repo

you can play with this

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.