Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ plugins {
alias(libs.plugins.android.lint) apply false
alias(libs.plugins.buildKonfig) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.apollo) apply false
}
28 changes: 28 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@file:OptIn(ApolloExperimental::class)

import com.apollographql.apollo.annotations.ApolloExperimental
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
import java.util.Properties

Expand All @@ -15,6 +18,8 @@ plugins {
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.ksp)
alias(libs.plugins.androidx.room)
alias(libs.plugins.apollo)

}

room {
Expand Down Expand Up @@ -92,6 +97,11 @@ kotlin {
// Firebase (GitLive KMP SDK — works on both Android & iOS)
implementation(libs.firebase.auth)
implementation(libs.firebase.firestore)

// Apollo
implementation(libs.apollo.runtime)
// Memory Cache
implementation(libs.apollo.normalized.cache)
}
}

Expand Down Expand Up @@ -148,4 +158,22 @@ buildkonfig {
localProperties.getProperty("SHOPIFY_REST_URL") ?: error("SHOPIFY_HOSTNAME not set in local.properties")
)
}
}
apollo {
service(name = "service") {
packageName.set("com.troves.data.source.remote.service.apollo.graphql")
srcDir(file("src/commonMain/graphql"))
generateDataBuilders.set(true)
val apiKey = localProperties.getProperty("SHOPIFY_API_KEY") ?: ""
val url = localProperties.getProperty("SHOPIFY_REST_URL") ?: ""


introspection {
endpointUrl.set("${url}graphql.json")

schemaFile.set(file("src/commonMain/graphql/schema.graphqls"))

headers.put("X-Shopify-Access-Token", apiKey)
}
}
}
28 changes: 28 additions & 0 deletions data/src/commonMain/graphql/Fragments.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Shared product selection (Shopify Admin API) used by every product query so a single
# Kotlin mapper (ProductCard.toProductDto) can populate the REST-shaped ProductDto.
fragment ProductCard on Product {
id
title
vendor
status
descriptionHtml
featuredImage {
url
}
priceRangeV2 {
minVariantPrice {
amount
}
}
images(first: 10) {
edges {
node {
url
}
}
}
options {
name
values
}
}
13 changes: 13 additions & 0 deletions data/src/commonMain/graphql/GetCollections.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query GetCollections($first: Int!, $query: String, $after: String) {
collections(first: $first, query: $query, after: $after) {
edges {
node {
id
title
image {
url
}
}
}
}
}
5 changes: 5 additions & 0 deletions data/src/commonMain/graphql/GetProductById.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query GetProductById($id: ID!) {
product(id: $id) {
...ProductCard
}
}
16 changes: 16 additions & 0 deletions data/src/commonMain/graphql/GetProducts.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
query GetProducts($first: Int!, $after: String, $sortKey: ProductSortKeys, $reverse: Boolean) {
products(first: $first, after: $after, sortKey: $sortKey, reverse: $reverse) {
edges {
cursor
node {
...ProductCard
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
15 changes: 15 additions & 0 deletions data/src/commonMain/graphql/GetProductsBySearch.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query GetProductsBySearch(
$first: Int!,
$query: String,
$after: String,
$sortKey: ProductSortKeys,
$reverse: Boolean
) {
products(first: $first, query: $query, after: $after, sortKey: $sortKey, reverse: $reverse) {
edges {
node {
...ProductCard
}
}
}
}
Loading