reactioncommerce / example-storefront

Example Storefront is Reaction Commerce’s headless ecommerce storefront - Next.js, GraphQL, React. Built using Apollo Client and the commerce-focused React UI components provided in the Storefront Component Library (reactioncommerce/reaction-component-library). It connects with Reaction backend with the GraphQL API.
https://www.mailchimp.com/developer/open-commerce
Apache License 2.0
606 stars 288 forks source link

Create a tags query in GraphQL #5

Closed nnnnat closed 6 years ago

nnnnat commented 6 years ago

@spencern commented on Fri Mar 30 2018

Summary Create a query to retreive tags associated with navigation in GraphQL for the provided shop.

Implementation

Schema

type Tag implements Node, Deletable {
  _id: ID!
  name: String!
  slug: String
  # type: String # OMIT: Introduced for Foray?
  metafields: [Metafield]
  position: Int
  relatedTags: [TagConnection]
  isDeleted: Boolean!
  isTopLevel: Boolean!
  #isVisible: Boolean! # OMIT: This is not editable or used. Keep in db but don't expose over Graphql.
  #groups: [String] # OMIT: Not used in core. Limits visibility to groups.
  shop: Shop!
  createdAt: DateTime!
  updatedAt: DateTime!
}

enum TagSortByField {
  _id
  name
  createdAt
  updatedAt
}

type TagEdge implements NodeEdge {
  cursor: ConnectionCursor!
  node: Tag
}

type TagConnection implements NodeConnection {
  edges: [TagEdge]
  nodes: [Tag]
  pageInfo: PageInfo!
  totalCount: Int!
}

Query

The root navigationTags query should have the following signature

# Returns a paged list of tags for a shop
tags(shopId: ID!, isTopLevel: Boolean, sortOrder: SortOrder = asc, sortBy: TagSortByField = createdAt): TagConnection

Also create a similar query within the Shop type

# Returns a paged list of tags for this shop
tags(isTopLevel: Boolean, sortOrder: SortOrder = asc, sortBy: TagSortByField = createdAt): TagConnection

Both queries return a TagConnection filtered by the arguments provided.

You'll need to implement Tag.relatedTags as a separate resolver. Figure out a way to throw an error if more than 1 level of relatedTags is requested.

Acceptance Criteria

nnnnat commented 6 years ago

Issue moved to reactioncommerce/reaction #4159 via ZenHub