Frontity GraphQL

Hello everyone … I am currently configuring my Frontity and I would like to know if it uses GraphQL to recover data ? If so, how do you proceed ?

Hello @Gray! Frontity does not use GraphQL to recover data. However, @frontity/wp-source package provides state.source.get API that returns an object that gives you info about the type of that link and related entities.

Example

import React from 'react';
import { connect } from 'frontity';

const Posts = ({ state }) => {
  const data = state.source.get(state.router.link); // returns an object similar to the one below

  console.log(data);
};

export default connect(Posts);

NB: The above code snippet requires the @frontity/wp-source and @frontity/tiny-router packages to be installed to return a response object like:

{
  // entity properties
  taxonomy: "category"
  id: 7

  // booleans that identify the type of path
  isArchive: true
  isCategory: true
  isTaxonomy: true

  // booleans that show the fetch status
  isFetching: false
  isReady: true

  // list of posts (if it's an archive)
  items: [{ type: "post", id: 60, link: "..." }, ...]
  total: 10
  totalPages: 1
}

We have written guides on how to fetch posts in our documentation: https://docs.frontity.org/api-reference-1/wordpress-source.

Happy Coding! :slightly_smiling_face:

1 Like