From 80d1c70e35474512263e3225daed55867e9e90b6 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Fri, 21 Jul 2023 16:05:40 -0700 Subject: [PATCH] refactor: query online for connect status --- .../DropdownConnectStatus.fragment.ts | 14 ++------ .../UserProfile/DropdownConnectStatus.vue | 36 ++++++++----------- composables/gql/fragment-masking.ts | 10 +++--- composables/gql/gql.ts | 9 ++--- composables/gql/graphql.ts | 12 ++----- composables/gql/index.ts | 4 +-- 6 files changed, 30 insertions(+), 55 deletions(-) diff --git a/components/UserProfile/DropdownConnectStatus.fragment.ts b/components/UserProfile/DropdownConnectStatus.fragment.ts index 3d91d29e2..474293f45 100644 --- a/components/UserProfile/DropdownConnectStatus.fragment.ts +++ b/components/UserProfile/DropdownConnectStatus.fragment.ts @@ -1,15 +1,7 @@ import { graphql } from '~/composables/gql/gql'; -export const TEST_FRAGMENT = graphql(/* GraphQL */` - fragment TestFragment on Cloud { - error - } -`); - -export const TEST_QUERY = graphql(/* GraphQL */` - query cloudError { - cloud { - ...TestFragment - } +export const ONLINE_QUERY = graphql(/* GraphQL */` + query OnlineStatus { + online } `); diff --git a/components/UserProfile/DropdownConnectStatus.vue b/components/UserProfile/DropdownConnectStatus.vue index 04f596895..37d5e3377 100644 --- a/components/UserProfile/DropdownConnectStatus.vue +++ b/components/UserProfile/DropdownConnectStatus.vue @@ -1,43 +1,35 @@ diff --git a/composables/gql/fragment-masking.ts b/composables/gql/fragment-masking.ts index cf750b0c6..c000279ac 100644 --- a/composables/gql/fragment-masking.ts +++ b/composables/gql/fragment-masking.ts @@ -2,6 +2,7 @@ import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graph import type { FragmentDefinitionNode } from 'graphql'; import type { Incremental } from './graphql'; + export type FragmentType> = TDocumentType extends DocumentTypeDecoration< infer TType, any @@ -33,20 +34,21 @@ export function useFragment( _documentNode: DocumentTypeDecoration, fragmentType: ReadonlyArray>> | null | undefined ): ReadonlyArray | null | undefined; -export function useFragment ( +export function useFragment( _documentNode: DocumentTypeDecoration, fragmentType: FragmentType> | ReadonlyArray>> | null | undefined ): TType | ReadonlyArray | null | undefined { return fragmentType as any; } + export function makeFragmentData< F extends DocumentTypeDecoration, FT extends ResultOf -> (data: FT, _fragment: F): FragmentType { +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } -export function isFragmentReady ( +export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, data: FragmentType, any>> | null | undefined @@ -54,7 +56,7 @@ export function isFragmentReady ( const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ ?.deferredFields; - if (!deferredFields) { return true; } + if (!deferredFields) return true; const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; const fragName = fragDef?.name?.value; diff --git a/composables/gql/gql.ts b/composables/gql/gql.ts index 7d3df55cb..4de976065 100644 --- a/composables/gql/gql.ts +++ b/composables/gql/gql.ts @@ -13,8 +13,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document- * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { - "\n fragment TestFragment on Cloud {\n error\n }\n": types.TestFragmentFragmentDoc, - "\n query cloudError {\n cloud {\n ...TestFragment\n }\n }\n": types.cloudErrorDocument, + "\n query OnlineStatus {\n online\n }\n": types.OnlineStatusDocument, "\n fragment FragmentConfig on Config {\n error\n valid\n }\n": types.FragmentConfigFragmentDoc, "\n fragment FragmentOwner on Owner {\n avatar\n username\n }\n": types.FragmentOwnerFragmentDoc, "\n fragment FragmentRegistration on Registration {\n state\n expiration\n keyFile {\n contents\n }\n }\n": types.FragmentRegistrationFragmentDoc, @@ -39,11 +38,7 @@ export function graphql(source: string): unknown; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n fragment TestFragment on Cloud {\n error\n }\n"): (typeof documents)["\n fragment TestFragment on Cloud {\n error\n }\n"]; -/** - * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. - */ -export function graphql(source: "\n query cloudError {\n cloud {\n ...TestFragment\n }\n }\n"): (typeof documents)["\n query cloudError {\n cloud {\n ...TestFragment\n }\n }\n"]; +export function graphql(source: "\n query OnlineStatus {\n online\n }\n"): (typeof documents)["\n query OnlineStatus {\n online\n }\n"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/composables/gql/graphql.ts b/composables/gql/graphql.ts index dbc757a70..601dc0ef5 100644 --- a/composables/gql/graphql.ts +++ b/composables/gql/graphql.ts @@ -1586,15 +1586,10 @@ export type usersInput = { slim?: InputMaybe; }; -export type TestFragmentFragment = { __typename?: 'Cloud', error?: string | null } & { ' $fragmentName'?: 'TestFragmentFragment' }; - -export type cloudErrorQueryVariables = Exact<{ [key: string]: never; }>; +export type OnlineStatusQueryVariables = Exact<{ [key: string]: never; }>; -export type cloudErrorQuery = { __typename?: 'Query', cloud?: ( - { __typename?: 'Cloud' } - & { ' $fragmentRefs'?: { 'TestFragmentFragment': TestFragmentFragment } } - ) | null }; +export type OnlineStatusQuery = { __typename?: 'Query', online?: boolean | null }; export type FragmentConfigFragment = { __typename?: 'Config', error?: ConfigErrorState | null, valid?: boolean | null } & { ' $fragmentName'?: 'FragmentConfigFragment' }; @@ -1621,10 +1616,9 @@ export type serverStateQuery = { __typename?: 'Query', crashReportingEnabled?: b & { ' $fragmentRefs'?: { 'FragmentConfigFragment': FragmentConfigFragment } } ), cloud?: { __typename?: 'Cloud', error?: string | null, apiKey: { __typename?: 'ApiKeyResponse', valid: boolean, error?: string | null }, relay?: { __typename?: 'RelayResponse', status: string, error?: string | null } | null, cloud: { __typename?: 'CloudResponse', status: string, error?: string | null } } | null }; -export const TestFragmentFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"TestFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Cloud"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}}]}}]} as unknown as DocumentNode; export const FragmentConfigFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentConfig"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Config"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"valid"}}]}}]} as unknown as DocumentNode; export const FragmentOwnerFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentOwner"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Owner"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"avatar"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}}]} as unknown as DocumentNode; export const FragmentRegistrationFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentRegistration"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Registration"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"expiration"}},{"kind":"Field","name":{"kind":"Name","value":"keyFile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"contents"}}]}}]}}]} as unknown as DocumentNode; export const FragmentVarsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentVars"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Vars"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"regGen"}},{"kind":"Field","name":{"kind":"Name","value":"regState"}},{"kind":"Field","name":{"kind":"Name","value":"configError"}},{"kind":"Field","name":{"kind":"Name","value":"configValid"}}]}}]} as unknown as DocumentNode; -export const cloudErrorDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"cloudError"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cloud"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"TestFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"TestFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Cloud"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}}]}}]} as unknown as DocumentNode; +export const OnlineStatusDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"OnlineStatus"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"online"}}]}}]} as unknown as DocumentNode; export const serverStateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"serverState"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"owner"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FragmentOwner"}}]}},{"kind":"Field","name":{"kind":"Name","value":"info"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"os"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hostname"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"registration"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FragmentRegistration"}}]}},{"kind":"Field","name":{"kind":"Name","value":"crashReportingEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"vars"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FragmentVars"}}]}},{"kind":"Field","name":{"kind":"Name","value":"config"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"FragmentConfig"}}]}},{"kind":"Field","name":{"kind":"Name","value":"cloud"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"apiKey"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"valid"}},{"kind":"Field","name":{"kind":"Name","value":"error"}}]}},{"kind":"Field","name":{"kind":"Name","value":"relay"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"error"}}]}},{"kind":"Field","name":{"kind":"Name","value":"cloud"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"error"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentOwner"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Owner"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"avatar"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentRegistration"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Registration"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"expiration"}},{"kind":"Field","name":{"kind":"Name","value":"keyFile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"contents"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentVars"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Vars"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"regGen"}},{"kind":"Field","name":{"kind":"Name","value":"regState"}},{"kind":"Field","name":{"kind":"Name","value":"configError"}},{"kind":"Field","name":{"kind":"Name","value":"configValid"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"FragmentConfig"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Config"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"valid"}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/composables/gql/index.ts b/composables/gql/index.ts index c682b1e2f..f51599168 100644 --- a/composables/gql/index.ts +++ b/composables/gql/index.ts @@ -1,2 +1,2 @@ -export * from './fragment-masking'; -export * from './gql'; +export * from "./fragment-masking"; +export * from "./gql"; \ No newline at end of file