Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[menu-bar] Configure Apollo possibleTypes #62

Merged
merged 3 commits into from
Sep 21, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- Added local HTTP server to circumvent deep-link limitations. ([#52](https://github.com/expo/orbit/pull/52), [#53](https://github.com/expo/orbit/pull/53), [#54](https://github.com/expo/orbit/pull/54), [#55](https://github.com/expo/orbit/pull/55) by [@gabrieldonadel](https://github.com/gabrieldonadel))
- Show dock icon while windows are opened. ([#50](https://github.com/expo/orbit/pull/50) by [@gabrieldonadel](https://github.com/gabrieldonadel))
- Added Projects section to the menu bar. ([#46](https://github.com/expo/orbit/pull/46), [#59](https://github.com/expo/orbit/pull/59) by [@gabrieldonadel](https://github.com/gabrieldonadel))
- Added support for login to Expo. ([#41](https://github.com/expo/orbit/pull/41), [#43](https://github.com/expo/orbit/pull/43), [#44](https://github.com/expo/orbit/pull/44), [#45](https://github.com/expo/orbit/pull/45) by [@gabrieldonadel](https://github.com/gabrieldonadel))
- Added support for login to Expo. ([#41](https://github.com/expo/orbit/pull/41), [#43](https://github.com/expo/orbit/pull/43), [#44](https://github.com/expo/orbit/pull/44), [#45](https://github.com/expo/orbit/pull/45), [#62](https://github.com/expo/orbit/pull/62) by [@gabrieldonadel](https://github.com/gabrieldonadel))

### 🐛 Bug fixes

Expand Down
3 changes: 3 additions & 0 deletions apps/menu-bar/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const config: CodegenConfig = {
'./src/generated/schema.graphql': {
plugins: ['schema-ast'],
},
'./src/generated/graphql.possibleTypes.json': {
plugins: ['fragment-matcher'],
},
},
};

Expand Down
1 change: 1 addition & 0 deletions apps/menu-bar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@babel/preset-env": "^7.22.10",
"@babel/runtime": "^7.22.11",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/fragment-matcher": "^5.0.0",
"@graphql-codegen/schema-ast": "^4.0.0",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@graphql-codegen/typescript-react-apollo": "^3.3.7",
Expand Down
84 changes: 27 additions & 57 deletions apps/menu-bar/src/api/ApolloClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import {
FieldFunctionOptions,
HttpLink,
InMemoryCache,
NormalizedCacheObject,
concat,
ApolloProvider,
} from '@apollo/client';
import { MMKVWrapper, persistCache } from 'apollo3-cache-persist';
import { useEffect, useState } from 'react';

import Config from './Config';
import possibleTypesData from '../generated/graphql.possibleTypes.json';
import { storage } from '../modules/Storage';

const httpLink = new HttpLink({
Expand All @@ -27,7 +26,9 @@ const mergeBasedOnOffset = (existing: any[], incoming: any[], { args }: FieldFun
return merged;
};

const { possibleTypes } = possibleTypesData;
const cache = new InMemoryCache({
possibleTypes,
typePolicies: {
AppQuery: {
keyFields: ['byId', ['id']],
Expand Down Expand Up @@ -55,69 +56,38 @@ const cache = new InMemoryCache({
},
});

export const useApolloClient = () => {
const [sessionSecret, setSessionSecret] = useState(storage.getString('sessionSecret'));
const [client, setClient] = useState<ApolloClient<NormalizedCacheObject>>();

useEffect(() => {
async function init() {
await persistCache({
cache,
storage: new MMKVWrapper(storage),
key: 'apollo-cache-persist',
});

const authMiddlewareLink = new ApolloLink((operation, forward) => {
if (sessionSecret) {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
'expo-session': sessionSecret,
},
}));
}

return forward(operation);
});

setClient(
new ApolloClient({
link: concat(authMiddlewareLink, httpLink),
cache,
})
);
}

init();
}, [sessionSecret]);
const authMiddlewareLink = new ApolloLink((operation, forward) => {
const sessionSecret = storage.getString('sessionSecret');
if (sessionSecret) {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
'expo-session': sessionSecret,
},
}));
}

useEffect(() => {
const listener = storage.addOnValueChangedListener((changedKey) => {
if (changedKey === 'sessionSecret') {
setSessionSecret(storage.getString('sessionSecret'));
}
});
return forward(operation);
});

return () => {
listener.remove();
};
async function init() {
await persistCache({
cache,
storage: new MMKVWrapper(storage),
key: 'apollo-cache-persist',
});
}
init();

return {
client,
};
};
export const apolloClient = new ApolloClient({
link: concat(authMiddlewareLink, httpLink),
cache,
});

export function withApolloProvider<P extends object>(Component: React.ComponentType<P>) {
return (props: P) => {
const { client } = useApolloClient();

if (!client) {
return null;
}

return (
<ApolloProvider client={client}>
<ApolloProvider client={apolloClient}>
<Component {...props} />
</ApolloProvider>
);
Expand Down
47 changes: 47 additions & 0 deletions apps/menu-bar/src/generated/graphql.possibleTypes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"possibleTypes": {
"AccountUsageMetadata": [
"AccountUsageEASBuildMetadata"
],
"ActivityTimelineProjectActivity": [
"Build",
"BuildJob",
"Submission",
"Update"
],
"Actor": [
"Robot",
"SSOUser",
"User"
],
"BuildOrBuildJob": [
"Build",
"BuildJob"
],
"EASBuildOrClassicBuildJob": [
"Build",
"BuildJob"
],
"FcmSnippet": [
"FcmSnippetLegacy",
"FcmSnippetV1"
],
"NotificationMetadata": [
"BuildLimitThresholdExceededMetadata",
"BuildPlanCreditThresholdExceededMetadata",
"TestNotificationMetadata"
],
"PlanEnablement": [
"Concurrencies",
"EASTotalPlanEnablement"
],
"Project": [
"App",
"Snack"
],
"UserActor": [
"SSOUser",
"User"
]
}
}
50 changes: 48 additions & 2 deletions apps/menu-bar/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,7 @@ export enum BuildCredentialsSource {

export type BuildError = {
__typename?: 'BuildError';
buildPhase?: Maybe<BuildPhase>;
docsUrl?: Maybe<Scalars['String']['output']>;
errorCode: Scalars['String']['output'];
message: Scalars['String']['output'];
Expand Down Expand Up @@ -2431,6 +2432,50 @@ export type BuildParamsInput = {
sdkVersion?: InputMaybe<Scalars['String']['input']>;
};

export enum BuildPhase {
BuilderInfo = 'BUILDER_INFO',
CleanUpCredentials = 'CLEAN_UP_CREDENTIALS',
CompleteBuild = 'COMPLETE_BUILD',
ConfigureExpoUpdates = 'CONFIGURE_EXPO_UPDATES',
ConfigureXcodeProject = 'CONFIGURE_XCODE_PROJECT',
Custom = 'CUSTOM',
DownloadApplicationArchive = 'DOWNLOAD_APPLICATION_ARCHIVE',
EasBuildInternal = 'EAS_BUILD_INTERNAL',
FailBuild = 'FAIL_BUILD',
FixGradlew = 'FIX_GRADLEW',
InstallCustomTools = 'INSTALL_CUSTOM_TOOLS',
InstallDependencies = 'INSTALL_DEPENDENCIES',
InstallPods = 'INSTALL_PODS',
OnBuildCancelHook = 'ON_BUILD_CANCEL_HOOK',
OnBuildCompleteHook = 'ON_BUILD_COMPLETE_HOOK',
OnBuildErrorHook = 'ON_BUILD_ERROR_HOOK',
OnBuildSuccessHook = 'ON_BUILD_SUCCESS_HOOK',
ParseCustomWorkflowConfig = 'PARSE_CUSTOM_WORKFLOW_CONFIG',
PostInstallHook = 'POST_INSTALL_HOOK',
Prebuild = 'PREBUILD',
PrepareArtifacts = 'PREPARE_ARTIFACTS',
PrepareCredentials = 'PREPARE_CREDENTIALS',
PrepareProject = 'PREPARE_PROJECT',
PreInstallHook = 'PRE_INSTALL_HOOK',
PreUploadArtifactsHook = 'PRE_UPLOAD_ARTIFACTS_HOOK',
Queue = 'QUEUE',
ReadAppConfig = 'READ_APP_CONFIG',
ReadPackageJson = 'READ_PACKAGE_JSON',
RestoreCache = 'RESTORE_CACHE',
RunExpoDoctor = 'RUN_EXPO_DOCTOR',
RunFastlane = 'RUN_FASTLANE',
RunGradlew = 'RUN_GRADLEW',
SaveCache = 'SAVE_CACHE',
SetUpBuildEnvironment = 'SET_UP_BUILD_ENVIRONMENT',
SpinUpBuilder = 'SPIN_UP_BUILDER',
StartBuild = 'START_BUILD',
Unknown = 'UNKNOWN',
UploadApplicationArchive = 'UPLOAD_APPLICATION_ARCHIVE',
/** @deprecated No longer supported */
UploadArtifacts = 'UPLOAD_ARTIFACTS',
UploadBuildArtifacts = 'UPLOAD_BUILD_ARTIFACTS'
}

export type BuildPlanCreditThresholdExceededMetadata = {
__typename?: 'BuildPlanCreditThresholdExceededMetadata';
account: Account;
Expand Down Expand Up @@ -5835,7 +5880,7 @@ export type AppForPinnedListFragment = { __typename?: 'App', id: string, name: s
export type GetAppsForPinnedListQueryVariables = Exact<{ [key: string]: never; }>;


export type GetAppsForPinnedListQuery = { __typename?: 'RootQuery', viewer?: { __typename?: 'User', pinnedApps: Array<{ __typename?: 'App', id: string, name: string, slug: string, latestActivity: any, icon?: { __typename?: 'AppIcon', url: string, primaryColor?: string | null } | null, ownerAccount: { __typename?: 'Account', name: string } }>, accounts: Array<{ __typename?: 'Account', id: string, appsPaginated: { __typename?: 'AccountAppsConnection', edges: Array<{ __typename?: 'AccountAppsEdge', cursor: string, node: { __typename?: 'App', id: string, name: string, slug: string, latestActivity: any, icon?: { __typename?: 'AppIcon', url: string, primaryColor?: string | null } | null, ownerAccount: { __typename?: 'Account', name: string } } }> } }> } | null };
export type GetAppsForPinnedListQuery = { __typename?: 'RootQuery', meUserActor?: { __typename?: 'SSOUser', id: string, pinnedApps: Array<{ __typename?: 'App', id: string, name: string, slug: string, latestActivity: any, icon?: { __typename?: 'AppIcon', url: string, primaryColor?: string | null } | null, ownerAccount: { __typename?: 'Account', name: string } }>, accounts: Array<{ __typename?: 'Account', id: string, appsPaginated: { __typename?: 'AccountAppsConnection', edges: Array<{ __typename?: 'AccountAppsEdge', cursor: string, node: { __typename?: 'App', id: string, name: string, slug: string, latestActivity: any, icon?: { __typename?: 'AppIcon', url: string, primaryColor?: string | null } | null, ownerAccount: { __typename?: 'Account', name: string } } }> } }> } | { __typename?: 'User', id: string, pinnedApps: Array<{ __typename?: 'App', id: string, name: string, slug: string, latestActivity: any, icon?: { __typename?: 'AppIcon', url: string, primaryColor?: string | null } | null, ownerAccount: { __typename?: 'Account', name: string } }>, accounts: Array<{ __typename?: 'Account', id: string, appsPaginated: { __typename?: 'AccountAppsConnection', edges: Array<{ __typename?: 'AccountAppsEdge', cursor: string, node: { __typename?: 'App', id: string, name: string, slug: string, latestActivity: any, icon?: { __typename?: 'AppIcon', url: string, primaryColor?: string | null } | null, ownerAccount: { __typename?: 'Account', name: string } } }> } }> } | null };

export const AppForPinnedListFragmentDoc = gql`
fragment AppForPinnedList on App {
Expand All @@ -5854,7 +5899,8 @@ export const AppForPinnedListFragmentDoc = gql`
`;
export const GetAppsForPinnedListDocument = gql`
query GetAppsForPinnedList {
viewer {
meUserActor {
id
pinnedApps {
...AppForPinnedList
}
Expand Down
44 changes: 44 additions & 0 deletions apps/menu-bar/src/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ enum BuildCredentialsSource {
}

type BuildError {
buildPhase: BuildPhase
docsUrl: String
errorCode: String!
message: String!
Expand Down Expand Up @@ -1615,6 +1616,49 @@ input BuildParamsInput {
sdkVersion: String
}

enum BuildPhase {
BUILDER_INFO
CLEAN_UP_CREDENTIALS
COMPLETE_BUILD
CONFIGURE_EXPO_UPDATES
CONFIGURE_XCODE_PROJECT
CUSTOM
DOWNLOAD_APPLICATION_ARCHIVE
EAS_BUILD_INTERNAL
FAIL_BUILD
FIX_GRADLEW
INSTALL_CUSTOM_TOOLS
INSTALL_DEPENDENCIES
INSTALL_PODS
ON_BUILD_CANCEL_HOOK
ON_BUILD_COMPLETE_HOOK
ON_BUILD_ERROR_HOOK
ON_BUILD_SUCCESS_HOOK
PARSE_CUSTOM_WORKFLOW_CONFIG
POST_INSTALL_HOOK
PREBUILD
PREPARE_ARTIFACTS
PREPARE_CREDENTIALS
PREPARE_PROJECT
PRE_INSTALL_HOOK
PRE_UPLOAD_ARTIFACTS_HOOK
QUEUE
READ_APP_CONFIG
READ_PACKAGE_JSON
RESTORE_CACHE
RUN_EXPO_DOCTOR
RUN_FASTLANE
RUN_GRADLEW
SAVE_CACHE
SET_UP_BUILD_ENVIRONMENT
SPIN_UP_BUILDER
START_BUILD
UNKNOWN
UPLOAD_APPLICATION_ARCHIVE
UPLOAD_ARTIFACTS @deprecated
UPLOAD_BUILD_ARTIFACTS
}

type BuildPlanCreditThresholdExceededMetadata {
account: Account!
buildCreditUsage: Int!
Expand Down
3 changes: 2 additions & 1 deletion apps/menu-bar/src/graphql/apps.gql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fragment AppForPinnedList on App {
}

query GetAppsForPinnedList {
viewer {
meUserActor {
id
pinnedApps {
...AppForPinnedList
}
Expand Down
4 changes: 2 additions & 2 deletions apps/menu-bar/src/hooks/useGetPinnedApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const useGetPinnedApps = () => {
fetchPolicy: 'cache-and-network',
});

const pinnedApps = data?.viewer?.pinnedApps;
const accounts = data?.viewer?.accounts;
const pinnedApps = data?.meUserActor?.pinnedApps;
const accounts = data?.meUserActor?.accounts;

const apps = useMemo(() => {
let apps: PinnedApp[] = [];
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,14 @@
"@graphql-tools/utils" "^10.0.0"
tslib "~2.5.0"

"@graphql-codegen/fragment-matcher@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@graphql-codegen/fragment-matcher/-/fragment-matcher-5.0.0.tgz#2a016715e42e8f21aa08830f34a4d0a930e660fe"
integrity sha512-mbash9E8eY6RSMSNrrO+C9JJEn8rdr8ORaxMpgdWL2qe2q/TlLUCE3ZvQvHkSc7GjBnMEk36LncA8ApwHR2BHg==
dependencies:
"@graphql-codegen/plugin-helpers" "^5.0.0"
tslib "~2.5.0"

"@graphql-codegen/plugin-helpers@^2.7.2":
version "2.7.2"
resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-2.7.2.tgz#6544f739d725441c826a8af6a49519f588ff9bed"
Expand Down