diff --git a/codegen.yml b/codegen.yml index c5d2d3fa..2219d008 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,5 +1,5 @@ overwrite: true -schema: 'http://v2.discours.io/graphql' +schema: 'https://testapi.discours.io' generates: src/graphql/introspec.gen.ts: plugins: diff --git a/src/graphql/cache.ts b/src/graphql/cache.ts index 69ebaa11..36132d2f 100644 --- a/src/graphql/cache.ts +++ b/src/graphql/cache.ts @@ -1,8 +1,10 @@ import { cacheExchange, CacheExchangeOpts } from '@urql/exchange-graphcache' -// import schema from './introspec.gen' +// import schema from './introspec.gen' +// NOTE: include codegened introspection schema when needed + +// TODO: use urql-provided caching export const cache = cacheExchange({ - // TODO: include introspection schema when needed keys: { Shout: (data) => data.slug, Author: (data) => data.slug, diff --git a/src/graphql/client.ts b/src/graphql/client.ts new file mode 100644 index 00000000..2c7a3e70 --- /dev/null +++ b/src/graphql/client.ts @@ -0,0 +1,30 @@ +import { createClient } from '@urql/core' +import { isDev } from '../utils/config' + +const localClient = (options) => { + const url = 'http://localhost:8080' + let c + try { + c = createClient({ ...options, url }) + console.info('[graphql] using local client') + } catch (error) { + console.error(error) + c = createClient(options) + console.info( + `[graphql] using ${options.url.replace('https://', '').replace('/graphql', '').replace('/', '')}` + ) + } + return c +} + +export const initClient = (options) => { + try { + if (isDev) { + console.info('[graphql] devmode detected') + return localClient(options) + } else return createClient(options) + } catch (error) { + console.error(error) + return localClient(options) + } +} diff --git a/src/graphql/query/topic-by-slug.ts b/src/graphql/query/topic-by-slug.ts index 0e440496..7ed25aa2 100644 --- a/src/graphql/query/topic-by-slug.ts +++ b/src/graphql/query/topic-by-slug.ts @@ -7,8 +7,6 @@ export default gql` body slug pic - parents - children # community stat { _id: shouts diff --git a/src/graphql/query/topics-all.ts b/src/graphql/query/topics-all.ts index e838f8e5..e20575f2 100644 --- a/src/graphql/query/topics-all.ts +++ b/src/graphql/query/topics-all.ts @@ -13,8 +13,8 @@ export default gql` _id: shouts shouts authors - # viewed followers + # viewed } } } diff --git a/src/graphql/query/topics-by-author.ts b/src/graphql/query/topics-by-author.ts index 90e7be5b..eaae45bc 100644 --- a/src/graphql/query/topics-by-author.ts +++ b/src/graphql/query/topics-by-author.ts @@ -12,7 +12,6 @@ export default gql` _id: shouts shouts authors - # viewed followers } } diff --git a/src/graphql/query/topics-by-community.ts b/src/graphql/query/topics-by-community.ts index 6545289e..32213a51 100644 --- a/src/graphql/query/topics-by-community.ts +++ b/src/graphql/query/topics-by-community.ts @@ -12,7 +12,6 @@ export default gql` _id: shouts shouts authors - # viewed followers } } diff --git a/src/graphql/query/topics-random.ts b/src/graphql/query/topics-random.ts index 2cf88e20..b85bf45c 100644 --- a/src/graphql/query/topics-random.ts +++ b/src/graphql/query/topics-random.ts @@ -13,7 +13,6 @@ export default gql` _id: shouts shouts authors - # viewed followers } } diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 493f21a1..a57bc253 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -644,10 +644,8 @@ export type Token = { export type Topic = { body?: Maybe - children?: Maybe>> community: Community oid?: Maybe - parents?: Maybe>> pic?: Maybe slug: Scalars['String'] stat?: Maybe @@ -656,9 +654,7 @@ export type Topic = { export type TopicInput = { body?: InputMaybe - children?: InputMaybe>> community: Scalars['String'] - parents?: InputMaybe>> pic?: InputMaybe slug: Scalars['String'] title?: InputMaybe @@ -671,7 +667,7 @@ export type TopicStat = { rating?: Maybe reacted: Scalars['Int'] shouts: Scalars['Int'] - viewed: Scalars['Int'] + viewed?: Maybe } export type User = {