Did you make the fragment for the entry fields? Let's walk through it.

In src/helpers/fragments.js, define the ENTRY_FIELDS fragment:

export const ENTRY_FIELDS = gql`
  fragment EntryFields on Entry {
    id
    habitId
    notes
    date
    completed
  }
`;

Let's head over to Habit.js and use the fragment. First, import the fragment:

import { ENTRY_FIELDS } from "./helpers/fragments";

Then, update the entries query to use the fragment:

export const ENTRIES_QUERY = gql`
  query ENTRIES_QUERY($id: ID!) {
    getEntriesByHabitId(id: $id) {
      ...EntryFields
    }
  }
  ${ENTRY_FIELDS}
`;

Now let's do the same thing in AddEntry.js. First, update the import:

import { ENTRY_FIELDS } from "./helpers/fragments";

Then, update the create entry mutation:

const CREATE_ENTRY_MUTATION = gql`
  mutation CREATE_ENTRY_MUTATION($input: NewEntryInput) {
    createEntry(input: $input) {
      ...EntryFields
    }
  }
  ${ENTRY_FIELDS}
`;

Everything should be working as expected, but now any time the fields on the Entry data type changes, we've only got one place to update. Great work!

 

I finished! On to the next chapter