0

I'm using Lighthouse with GraphQL and trying to figure out how to pass in a param into a relationship (I have a feeling I'm not using the right terms).

Here's what I got:


type Entry {
  id: ID!
  site_id: ID
  slug: String!
  admin_note: String
  type: String!
  sub_type: String
  content(status: String): EntryContent @hasOne
  versions: [EntryContent!]! @hasMany
  magazineIssues: [MagazineIssue]! @belongsToMany
  contentPackages: [ContentPackage]! @belongsToMany
  published_at: DateTime
  created_at: DateTime
  updated_at: DateTime
  deleted_at: DateTime
}

# Query
entries(first: Int!, page: Int, type: String @eq, site_id: ID @eq, status: String): [Entry!]! @paginate

export const ALL_SITE_ENTRIES = gql`
  query Entries($first: Int!, $page: Int, $type: String, $site_id: ID, $status: String) {
    entries(first: $first, page: $page, type: $type, site_id: $site_id, status: $status) {
      data {
        ...EntryDetails
        content(status: $status) {
          id
          title
          status
        }
      }
      paginatorInfo {
        currentPage
        lastPage
        total
      }
    }
  }
  ${EntryDetailsFragment}
`

I'm querying Entries with paginate, but I need to pass in a param for a specific content status. I tried the one above and I'm getting the error:

message: "Fields \"content\" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional."

But I don't understand why I'd need an alias for param like this. Is there a way to pass in a param into a relationship/query?

Thanks!

cbloss793
  • 1,555
  • 4
  • 19
  • 30

1 Answers1

0

So after insane trial and error, I came up with some sort of solution only to find out our Laravel relationship isn't quite returning what it is. However, for anyone who wants an example on how to query on a nested relationship, here's a good example that works on a different column:

extend type Query {
  entries(first: Int!, 
    page: Int, 
    type: String @eq, 
    site_id: ID @eq,
    hasContent: _ @whereHasConditions(relation: "content", columns: ["title"])
   ): [Entry!]! @paginate
}


export const ALL_SITE_ENTRIES = gql`
  query Entries($first: Int!, $page: Int, $type: String, $site_id: ID, $title: Mixed) {
    entries(
        first: $first, 
        page: $page, 
        type: $type, 
        site_id: $site_id, 
        hasContent: {column: TITLE, operator: LIKE, value: $title}
      ) {
      data {
        ...EntryDetails
        content{
          id
          title
          status
        }
      }
      paginatorInfo {
        currentPage
        lastPage
        total
      }
    }
  }
  ${EntryDetailsFragment}
`

Note: to get the full LIKE experience, make sure to add %% around your text that you're searching.

Hope this helps someone. I really needed more examples to go off of. :)

cbloss793
  • 1,555
  • 4
  • 19
  • 30