-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from cesmii/feature/custom-graphql-endpoints
Custom GraphQL Endpoints
- Loading branch information
Showing
18 changed files
with
174 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
<template> | ||
<NuxtPwaManifest/> | ||
<NuxtPwaManifest /> | ||
<NuxtLayout> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { provideApolloClient } from "./lib/graphql"; | ||
provideApolloClient(); | ||
</script> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { InMemoryCache, HttpLink, ApolloClient } from "@apollo/client/core"; | ||
import { setContext } from "@apollo/client/link/context"; | ||
import { DefaultApolloClient } from "@vue/apollo-composable"; | ||
|
||
import { GRAPHL_TOKEN_KEY } from "../consts"; | ||
import { useGraphQLStore } from "~/stores/graphql"; | ||
|
||
|
||
|
||
export function provideApolloClient() { | ||
const graphqlStore = useGraphQLStore(); | ||
const jwtCookie = useCookie(GRAPHL_TOKEN_KEY); | ||
|
||
const cache = new InMemoryCache({ | ||
typePolicies: { | ||
AttributesGetTimeSeriesRecord: { | ||
keyFields: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const httpLink = new HttpLink({ | ||
// Get latest GraphQL endpoint, in case the user switched to a different server. | ||
uri: () => graphqlStore.endpoint, | ||
}); | ||
|
||
// Add JWT to GraphQL requests. | ||
const authLink = setContext((_, { headers }) => { | ||
if(!jwtCookie.value) { | ||
return { headers }; | ||
} | ||
|
||
return { | ||
headers: { | ||
...headers, | ||
authorization: `Bearer ${jwtCookie.value}`, | ||
}, | ||
}; | ||
}); | ||
|
||
const apolloClient = new ApolloClient({ | ||
cache, | ||
link: authLink.concat(httpLink), | ||
}); | ||
|
||
provide(DefaultApolloClient, apolloClient); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./useEquipmentDetailWithOEE"; | ||
export * from "./useEquipmentIds"; | ||
export * from "./useEquipmentWithOEE"; |
20 changes: 10 additions & 10 deletions
20
...osables/useAsyncEquipmentDetailWithOEE.ts → ...nd/lib/hooks/useEquipmentDetailWithOEE.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { useQuery } from "@vue/apollo-composable"; | ||
|
||
import { GetEquipmentDetailDocument } from "~/generated/graphql/operations"; | ||
import { parseEquipmentWithOEE } from "~/lib/equipment"; | ||
import { parseEquipmentWithOEE } from "~/lib/equipment"; | ||
|
||
|
||
|
||
export default function useAsyncEquipmentDetailWithOEE(id: string) { | ||
export function useEquipmentDetailWithOEE(id: string) { | ||
// TODO: Use equipment timezone instead of user timezone. | ||
const startTime = new Date(); | ||
startTime.setHours(0, 0, 0, 0); | ||
const endTime = new Date(startTime); | ||
endTime.setDate(startTime.getDate() + 1); | ||
|
||
return useAsyncQuery( | ||
const query = useQuery( | ||
GetEquipmentDetailDocument, | ||
{ | ||
id, | ||
startTime: startTime.toISOString(), | ||
endTime: endTime.toISOString(), | ||
}, | ||
"default", | ||
{ }, | ||
{ | ||
transform: (res) => { | ||
return res.equipment ? parseEquipmentWithOEE(res.equipment) : undefined; | ||
}, | ||
}, | ||
); | ||
|
||
return { | ||
query, | ||
data: computed(() => query.result.value?.equipment ? parseEquipmentWithOEE(query.result.value.equipment) : undefined), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.