diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-13 16:42:50 +0100 | 
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-13 16:52:33 +0100 | 
| commit | 5bc55ac0a801cbe82c41a10f7e680612be4deaf8 (patch) | |
| tree | 9dbfada52bdc4750cca60e9bc8b8fd63cf9a4737 /src/services/graphql/homepage.ts | |
| parent | 8c836de71b47744ec3e99cb8b3c853528fa66b52 (diff) | |
chore: create homepage with graphql data
Diffstat (limited to 'src/services/graphql/homepage.ts')
| -rw-r--r-- | src/services/graphql/homepage.ts | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/src/services/graphql/homepage.ts b/src/services/graphql/homepage.ts new file mode 100644 index 0000000..6ea71ac --- /dev/null +++ b/src/services/graphql/homepage.ts @@ -0,0 +1,36 @@ +import { gql } from 'graphql-request'; +import { +  fetchHomePageReturn, +  getHomePageReturn, +  HomePage, +  HomePageResponse, +} from '@ts/types/homepage'; +import { getGraphQLClient } from './client'; + +export const fetchHomepage: fetchHomePageReturn = async () => { +  const client = getGraphQLClient(); +  const query = gql` +    query HomePage { +      nodeByUri(uri: "/") { +        ... on Page { +          id +          content +        } +      } +    } +  `; + +  try { +    const response: HomePageResponse = await client.request(query); +    return response; +  } catch (error) { +    console.error(JSON.stringify(error, undefined, 2)); +    process.exit(1); +  } +}; + +export const getHomePage: getHomePageReturn = async () => { +  const rawHomePage = await fetchHomepage(); +  const homePage: HomePage = rawHomePage.nodeByUri; +  return homePage; +}; | 
