Skip to content

Commit

Permalink
#3 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bennobuilder committed Sep 12, 2024
1 parent a872fe0 commit cf56c7d
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 63 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@
"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
]
],

// Typescript settings
// https://gql-tada.0no.co/get-started/installation#vscode-setup
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
2 changes: 1 addition & 1 deletion apps/sfy-chrome-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@blgc/utils": "^0.0.18",
"@repo/ui": "workspace:*",
"feature-fetch": "^0.0.22",
"feature-fetch": "^0.0.25",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/sfy-eu-blocks-app/admin-block-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@shopify/ui-extensions": "2024.7.0",
"@shopify/ui-extensions-react": "2024.7.0",
"eprel-client": "^0.0.16",
"feature-fetch": "^0.0.22",
"feature-fetch": "^0.0.25",
"feature-form": "^0.0.27",
"feature-react": "^0.0.23",
"react": "^18.3.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const coreApiConfig = {
baseUrl: 'https://vip-entering-depot-colorado.trycloudflare.com' // TODO: Find way to sync url from api-core-node
baseUrl: 'https://miracle-translate-contributor-cartridge.trycloudflare.com' // TODO: Find way to sync url from api-core-node
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Err, FetchError, Ok, TResult } from 'feature-fetch';
import { Err, FetchError, getQueryString, Ok, TDocumentInput, TResult } from 'feature-fetch';

import { cx } from './context';

export async function q<
GVariables extends Record<string, any>,
GSucessResponseData extends Record<string, any>
>(query: string, variables: GVariables): Promise<TResult<GSucessResponseData, FetchError>> {
const result = await cx().query<GSucessResponseData, GVariables>(query, {
GSucessResponseData extends Record<string, any>,
GVariables extends Record<string, any>
>(
query: TDocumentInput<GSucessResponseData, GVariables>,
variables: GVariables
): Promise<TResult<GSucessResponseData, FetchError>> {
const maybeQueryString = getQueryString(query);
if (maybeQueryString.isErr()) {
return Err(maybeQueryString.error);
}

const result = await cx().query<GSucessResponseData, GVariables>(maybeQueryString.value, {
variables
});

Expand Down
8 changes: 4 additions & 4 deletions apps/sfy-eu-blocks-app/app/shopify.app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension_directories = [
]
name = "eu-blocks"
handle = "eu-blocks"
application_url = "https://indices-gadgets-seniors-app.trycloudflare.com"
application_url = "https://canon-formed-betting-employees.trycloudflare.com"
embedded = true

[build]
Expand All @@ -22,9 +22,9 @@ scopes = "read_files,read_locales,read_products,read_themes,write_files,write_pr

[auth]
redirect_urls = [
"https://indices-gadgets-seniors-app.trycloudflare.com/auth/callback",
"https://indices-gadgets-seniors-app.trycloudflare.com/auth/shopify/callback",
"https://indices-gadgets-seniors-app.trycloudflare.com/api/auth/callback"
"https://canon-formed-betting-employees.trycloudflare.com/auth/callback",
"https://canon-formed-betting-employees.trycloudflare.com/auth/shopify/callback",
"https://canon-formed-betting-employees.trycloudflare.com/api/auth/callback"
]

[webhooks]
Expand Down
2 changes: 1 addition & 1 deletion apps/sfy-eu-blocks-app/checkout-ui-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@shopify/ui-extensions": "2024.7.0",
"@shopify/ui-extensions-react": "2024.7.0",
"eprel-client": "^0.0.16",
"feature-fetch": "^0.0.22",
"feature-fetch": "^0.0.25",
"feature-react": "^0.0.23",
"feature-state": "^0.0.23",
"react": "^18.3.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const coreApiConfig = {
baseUrl: 'https://vip-entering-depot-colorado.trycloudflare.com' // TODO: Find way to sync url from api-core-node
baseUrl: 'https://miracle-translate-contributor-cartridge.trycloudflare.com' // TODO: Find way to sync url from api-core-node
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Err, FetchError, Ok, TResult } from 'feature-fetch';
import { Err, FetchError, getQueryString, Ok, TDocumentInput, TResult } from 'feature-fetch';

import { cx } from './context';

export async function q<
GVariables extends Record<string, any>,
GSucessResponseData extends Record<string, any>
>(query: string, variables: GVariables): Promise<TResult<GSucessResponseData, FetchError>> {
const result = await cx().query<GSucessResponseData, GVariables>(query, {
GSucessResponseData extends Record<string, any>,
GVariables extends Record<string, any>
>(
query: TDocumentInput<GSucessResponseData, GVariables>,
variables: GVariables
): Promise<TResult<GSucessResponseData, FetchError>> {
const maybeQueryString = getQueryString(query);
if (maybeQueryString.isErr()) {
return Err(maybeQueryString.error);
}

const result = await cx().query<GSucessResponseData, GVariables>(maybeQueryString.value, {
variables
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Err, FetchError, Ok, TResult } from 'feature-fetch';
import { Err, FetchError, getQueryString, Ok, TDocumentInput, TResult } from 'feature-fetch';

import { cx } from './context';

export async function q<
GVariables extends Record<string, any>,
GSucessResponseData extends Record<string, any>
>(query: string, variables: GVariables): Promise<TResult<GSucessResponseData, FetchError>> {
const result = await cx().query<GSucessResponseData, GVariables>(query, {
GSucessResponseData extends Record<string, any>,
GVariables extends Record<string, any>
>(
query: TDocumentInput<GSucessResponseData, GVariables>,
variables: GVariables
): Promise<TResult<GSucessResponseData, FetchError>> {
const maybeQueryString = getQueryString(query);
if (maybeQueryString.isErr()) {
return Err(maybeQueryString.error);
}

const result = await cx().query<GSucessResponseData, GVariables>(maybeQueryString.value, {
variables
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Err, FetchError, Ok, TResult } from 'feature-fetch';
import { Err, FetchError, getQueryString, Ok, TDocumentInput, TResult } from 'feature-fetch';

import { cx } from './context';

export async function q<
GVariables extends Record<string, any>,
GSucessResponseData extends Record<string, any>
>(query: string, variables: GVariables): Promise<TResult<GSucessResponseData, FetchError>> {
const result = await cx().query<GSucessResponseData, GVariables>(query, {
GSucessResponseData extends Record<string, any>,
GVariables extends Record<string, any>
>(
query: TDocumentInput<GSucessResponseData, GVariables>,
variables: GVariables
): Promise<TResult<GSucessResponseData, FetchError>> {
const maybeQueryString = getQueryString(query);
if (maybeQueryString.isErr()) {
return Err(maybeQueryString.error);
}

const result = await cx().query<GSucessResponseData, GVariables>(maybeQueryString.value, {
variables
});

Expand Down
2 changes: 1 addition & 1 deletion packages/api-core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"homepage": "",
"dependencies": {
"feature-fetch": "^0.0.22"
"feature-fetch": "^0.0.25"
},
"devDependencies": {
"@blgc/config": "^0.0.23",
Expand Down
2 changes: 1 addition & 1 deletion packages/sfy-app-session-storage-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"homepage": "",
"dependencies": {
"feature-fetch": "^0.0.22"
"feature-fetch": "^0.0.25"
},
"peerDependencies": {
"@shopify/shopify-api": "^11.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/sfy-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graphql-env.d.ts
3 changes: 2 additions & 1 deletion packages/sfy-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"dependencies": {
"@shopify/liquid-html-parser": "^2.0.3",
"@shopify/prettier-plugin-liquid": "^1.5.0",
"feature-fetch": "^0.0.22",
"feature-fetch": "^0.0.25",
"gql.tada": "^1.8.7",
"prettier": "^3.3.3"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function createFileMutation(
variables: TCreateFileMutationVariables,
query: TQuery
): Promise<TResult<TCreateFileMutationResponseData, FetchError>> {
return query<TCreateFileMutationVariables, TCreateFileMutationResponseData>(
return query<TCreateFileMutationResponseData, TCreateFileMutationVariables>(
gql`
mutation CreateFile($files: [FileCreateInput!]!) {
fileCreate(files: $files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function deleteMetafieldMutation(
variables: TDeleteMetafieldMutationVariables,
query: TQuery
): Promise<TResult<TDeleteMetafieldMutationResponseData, FetchError>> {
return query<TDeleteMetafieldMutationVariables, TDeleteMetafieldMutationResponseData>(
return query<TDeleteMetafieldMutationResponseData, TDeleteMetafieldMutationVariables>(
gql`
mutation DeleteMetafield($productId: ID!, $namespace: String!, $key: String!) {
metafieldsDelete(metafields: [{ ownerId: $productId, namespace: $namespace, key: $key }]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function updateMetafieldMutation(
variables: TUpdateMetafieldVariables,
query: TQuery
): Promise<TResult<TUpdateMetafieldResponseData, FetchError>> {
return query<TUpdateMetafieldVariables, TUpdateMetafieldResponseData>(
return query<TUpdateMetafieldResponseData, TUpdateMetafieldVariables>(
gql`
mutation UpdateMetafield(
$productId: ID!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getGenericFileUrlsQuery(
variables: TGetFileUrlsQueryVariables,
query: TQuery
): Promise<TResult<TGetFileUrlsQueryResponseData, FetchError>> {
return query<TGetFileUrlsQueryVariables, TGetFileUrlsQueryResponseData>(
return query<TGetFileUrlsQueryResponseData, TGetFileUrlsQueryVariables>(
gql`
query GetGenericFileUrls($ids: [ID!]!) {
nodes(ids: $ids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getMetafieldValueQuery(
variables: TGetMetafieldValueQueryVariables,
query: TQuery
): Promise<TResult<TGetMetafieldValueQueryResponseData, FetchError>> {
return query<TGetMetafieldValueQueryVariables, TGetMetafieldValueQueryResponseData>(
return query<TGetMetafieldValueQueryResponseData, TGetMetafieldValueQueryVariables>(
gql`
query GetMetafieldValue($productId: ID!, $namespace: String!, $key: String!) {
product(id: $productId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function getMetafieldQuery<GKeys extends keyof TMetafieldProps>(
metafieldKeys: GKeys[],
query: TQuery
): Promise<TResult<TGetMetafieldQueryResponseData<GKeys>, FetchError>> {
return query<TGetMetafieldQueryVariables, TGetMetafieldQueryResponseData<GKeys>>(
return query<TGetMetafieldQueryResponseData<GKeys>, TGetMetafieldQueryVariables>(
gql`
query GetMetafield($productId: ID!, $namespace: String!, $key: String!) {
product(id: $productId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type TQuery } from '../types';
export async function getShopLocalesQuery(
query: TQuery
): Promise<TResult<TGetShopLocalesQueryResponseData, FetchError>> {
return query<{}, TGetShopLocalesQueryResponseData>(
return query<TGetShopLocalesQueryResponseData, {}>(
gql`
query GetShopLocales {
shopLocales {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getThemeFileQuery(
variables: TGetThemeFileQueryVariables,
query: TQuery
): Promise<TResult<TGetThemeFileQueryResponseData, FetchError>> {
return query<TGetThemeFileQueryVariables, TGetThemeFileQueryResponseData>(
return query<TGetThemeFileQueryResponseData, TGetThemeFileQueryVariables>(
gql`
query GetThemeFile($themeId: ID!, $filename: String!) {
theme(id: $themeId) {
Expand Down
8 changes: 4 additions & 4 deletions packages/sfy-utils/src/graphql/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type FetchError, type TResult } from 'feature-fetch';
import { type FetchError, type TDocumentInput, type TResult } from 'feature-fetch';

export type TQuery = <
GVariables extends Record<string, any>,
GSucessResponseData extends Record<string, any>
GSucessResponseData extends Record<string, any>,
GVariables extends Record<string, any>
>(
query: string,
query: TDocumentInput<GSucessResponseData, GVariables> | string,
variables: GVariables
) => Promise<TResult<GSucessResponseData, FetchError>>;
7 changes: 6 additions & 1 deletion packages/sfy-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"outDir": "./dist",
"rootDir": "./src",
"declarationDir": "./dist/types",
"baseUrl": "."
"baseUrl": ".",
"plugins": [{
"name": "gql.tada/ts-plugin",
"schema": "https://shopify.dev/admin-graphql-direct-proxy/2024-07",
"tadaOutputLocation": "./src/graphql-env.d.ts",
}]
},
"include": ["src"]
}
Loading

0 comments on commit cf56c7d

Please sign in to comment.