Skip to content

Fetching with OneGraphApolloClient and hooks #18

@bdougie

Description

@bdougie

Questions

Do you have examples of someone using OneGraph with @apollo/react-hooks?

My Attempt:

I am attempting to add caching in this draft PR: bdougie/open-sauced#379.

@apollo/react-hooks
apollo-cache-inmemory

import {useApolloClient, useQuery} from "@apollo/react-hooks";
import {gql} from "apollo-boost";

const fetchGoalsQuery = gql`
  query FetchGoals($name: String!) {
    gitHub {
      viewer {
        repository(name: $name) {
          id
          issues(first: 10, states: OPEN, orderBy: {direction: DESC, field: CREATED_AT}) {
            totalCount
            nodes {
              id
              title
              body
              number
              labels(first: 3) {
                nodes {
                  color
                  name
                  id
                }
              }
            }
          }
        }
      }
    }
  }
`;

// useQuery succeeds but the data and error returns undefined. 
const {data, error} = useQuery(fetchGoalsQuery, {name: "open-sauced-goals"});

// data and error are undefined
console.log("error", error);
console.log("data", data);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions