Skip to content

Commit

Permalink
initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Dec 4, 2023
1 parent f92dff4 commit 76a0416
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 13 deletions.
5 changes: 4 additions & 1 deletion examples/next/app/api/fuse/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createAPIRouteHandler } from 'fuse/next'
import persistedDocuments from '@/fuse/persisted-documents.json'

const files = require.context('../../../types', true, /\.ts$/)
files
.keys()
.filter((path: string) => path.includes('types/'))
.forEach(files)

const layer = createAPIRouteHandler()
const layer = createAPIRouteHandler({
persistedOperationsStore: persistedDocuments,
})

export const GET = layer
export const POST = layer
9 changes: 7 additions & 2 deletions examples/next/app/rsc/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as React from 'react'
import { registerClient, createClient, fetchExchange } from 'fuse/next/server'
import {
registerClient,
createClient,
fetchExchange,
persistedExchange,
} from 'fuse/next/server'

import { graphql } from '@/fuse'
import { LaunchItem } from '@/components/LaunchItem'
Expand All @@ -14,7 +19,7 @@ const { getClient } = registerClient(() =>
process.env.NODE_ENV === 'production'
? 'https://spacex-fuse.vercel.app/api/fuse'
: 'http://localhost:3000/api/fuse',
exchanges: [fetchExchange],
exchanges: [persistedExchange, fetchExchange],
}),
)

Expand Down
3 changes: 2 additions & 1 deletion examples/next/components/DatalayerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
cacheExchange,
fetchExchange,
createClient,
persistedExchange,
} from 'fuse/next/client'
import React from 'react'

Expand All @@ -17,7 +18,7 @@ export const DatalayerProvider = (props: any) => {
process.env.NODE_ENV === 'production'
? 'https://spacex-fuse.vercel.app/api/fuse'
: 'http://localhost:3000/api/fuse',
exchanges: [cacheExchange, ssr, fetchExchange],
exchanges: [cacheExchange, ssr, persistedExchange, fetchExchange],
suspense: true,
})

Expand Down
49 changes: 49 additions & 0 deletions examples/next/fuse/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export const LaunchFieldsFragmentDoc = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'launchDate' } },
Expand All @@ -303,6 +304,7 @@ export const SiteLocationFieldsFragmentDoc = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'latitude' } },
{ kind: 'Field', name: { kind: 'Name', value: 'longitude' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
Expand All @@ -325,6 +327,7 @@ export const LaunchSiteFieldsFragmentDoc = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'details' } },
Expand All @@ -335,6 +338,7 @@ export const LaunchSiteFieldsFragmentDoc = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'FragmentSpread',
name: { kind: 'Name', value: 'SiteLocationFields' },
Expand All @@ -355,6 +359,7 @@ export const LaunchSiteFieldsFragmentDoc = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'latitude' } },
{ kind: 'Field', name: { kind: 'Name', value: 'longitude' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
Expand All @@ -377,13 +382,15 @@ export const TotalCountFieldsFragmentDoc = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'totalCount' } },
],
},
},
],
} as unknown as DocumentNode<TotalCountFieldsFragment, unknown>
export const Launches_SsrDocument = {
__meta__: { hash: 'bb6e5ac452c5d08659b1855799a08ee2543a05ca' },
kind: 'Document',
definitions: [
{
Expand Down Expand Up @@ -411,6 +418,7 @@ export const Launches_SsrDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'launches' },
Expand All @@ -435,12 +443,17 @@ export const Launches_SsrDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'nodes' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: '__typename' },
},
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{
kind: 'FragmentSpread',
Expand Down Expand Up @@ -469,6 +482,7 @@ export const Launches_SsrDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'launchDate' } },
Expand All @@ -486,13 +500,15 @@ export const Launches_SsrDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'totalCount' } },
],
},
},
],
} as unknown as DocumentNode<Launches_SsrQuery, Launches_SsrQueryVariables>
export const Launches_RscDocument = {
__meta__: { hash: '616ad65c55a2a69941aff21ec3c1d0964773771f' },
kind: 'Document',
definitions: [
{
Expand Down Expand Up @@ -520,6 +536,7 @@ export const Launches_RscDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'launches' },
Expand All @@ -544,12 +561,17 @@ export const Launches_RscDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'nodes' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: '__typename' },
},
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{
kind: 'FragmentSpread',
Expand Down Expand Up @@ -578,6 +600,7 @@ export const Launches_RscDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'launchDate' } },
Expand All @@ -595,13 +618,15 @@ export const Launches_RscDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'totalCount' } },
],
},
},
],
} as unknown as DocumentNode<Launches_RscQuery, Launches_RscQueryVariables>
export const LaunchDetailsDocument = {
__meta__: { hash: '06f997a01891cf62f3b0499580b0d70a0d9658ae' },
kind: 'Document',
definitions: [
{
Expand All @@ -621,6 +646,7 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'node' },
Expand All @@ -637,6 +663,7 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'InlineFragment',
typeCondition: {
Expand All @@ -646,6 +673,10 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: '__typename' },
},
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{
Expand All @@ -663,6 +694,10 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: '__typename' },
},
{
kind: 'FragmentSpread',
name: { kind: 'Name', value: 'LaunchSiteFields' },
Expand All @@ -676,6 +711,10 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: '__typename' },
},
{
kind: 'Field',
name: { kind: 'Name', value: 'cost' },
Expand Down Expand Up @@ -714,6 +753,7 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'latitude' } },
{ kind: 'Field', name: { kind: 'Name', value: 'longitude' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
Expand All @@ -731,6 +771,7 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'details' } },
Expand All @@ -741,6 +782,7 @@ export const LaunchDetailsDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'FragmentSpread',
name: { kind: 'Name', value: 'SiteLocationFields' },
Expand All @@ -754,6 +796,7 @@ export const LaunchDetailsDocument = {
],
} as unknown as DocumentNode<LaunchDetailsQuery, LaunchDetailsQueryVariables>
export const PageLaunchesDocument = {
__meta__: { hash: '351e381d4b9bbd1da05483d9f533cc48dfcd2777' },
kind: 'Document',
definitions: [
{
Expand Down Expand Up @@ -781,6 +824,7 @@ export const PageLaunchesDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'launches' },
Expand All @@ -805,12 +849,17 @@ export const PageLaunchesDocument = {
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'nodes' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: '__typename' },
},
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
],
Expand Down
6 changes: 6 additions & 0 deletions examples/next/fuse/persisted-documents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"bb6e5ac452c5d08659b1855799a08ee2543a05ca": "fragment LaunchFields on Launch { __typename id image launchDate name } fragment TotalCountFields on QueryLaunchesList { __typename totalCount } query Launches_SSR($limit: Int, $offset: Int) { __typename launches(limit: $limit, offset: $offset) { __typename nodes { __typename id ...LaunchFields } ...TotalCountFields } }",
"616ad65c55a2a69941aff21ec3c1d0964773771f": "fragment LaunchFields on Launch { __typename id image launchDate name } fragment TotalCountFields on QueryLaunchesList { __typename totalCount } query Launches_RSC($limit: Int, $offset: Int) { __typename launches(limit: $limit, offset: $offset) { __typename nodes { __typename id ...LaunchFields } ...TotalCountFields } }",
"06f997a01891cf62f3b0499580b0d70a0d9658ae": "fragment LaunchSiteFields on Site { __typename details id location { __typename ...SiteLocationFields } name status } fragment SiteLocationFields on Location { __typename latitude longitude name region } query LaunchDetails($id: ID!) { __typename node(id: $id) { __typename ... on Launch { __typename details id image launchDate name rocket { __typename company cost country description } site { __typename ...LaunchSiteFields } } } }",
"351e381d4b9bbd1da05483d9f533cc48dfcd2777": "query PageLaunches($limit: Int, $offset: Int) { __typename launches(limit: $limit, offset: $offset) { __typename nodes { __typename id name } totalCount } }"
}
5 changes: 3 additions & 2 deletions examples/next/pages/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ssrExchange,
cacheExchange,
fetchExchange,
persistedExchange,
} from 'fuse/next/pages'

import { graphql } from '@/fuse'
Expand Down Expand Up @@ -65,7 +66,7 @@ export async function getServerSideProps() {
process.env.NODE_ENV === 'production'
? 'https://spacex-fuse.vercel.app/api/fuse'
: 'http://localhost:3000/api/fuse',
exchanges: [cacheExchange, ssrCache, fetchExchange],
exchanges: [cacheExchange, ssrCache, persistedExchange, fetchExchange],
})

await client.query(LaunchesQuery, { limit: 10, offset: 0 }).toPromise()
Expand All @@ -84,5 +85,5 @@ export default withGraphQLClient((ssrCache) => ({
process.env.NODE_ENV === 'production'
? 'https://spacex-fuse.vercel.app/api/fuse'
: 'http://localhost:3000/api/fuse',
exchanges: [cacheExchange, ssrCache, fetchExchange],
exchanges: [cacheExchange, ssrCache, persistedExchange, fetchExchange],
}))(Page)
2 changes: 1 addition & 1 deletion examples/next/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ type User implements Node {
firstName: String
id: ID!
name: String
}
}
3 changes: 3 additions & 0 deletions packages/core/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// src/next/client.ts
import { Exchange } from '@urql/core'
import { useQuery, UrqlProvider } from '@urql/next'
export * from 'urql'
export { UrqlProvider as Provider, useQuery }

export const persistedExchange: Exchange
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@
"@graphql-typed-document-node/core": "^3.2.0",
"@graphql-yoga/plugin-defer-stream": "^3.0.0",
"@graphql-yoga/plugin-disable-introspection": "^2.0.0",
"@graphql-yoga/plugin-persisted-operations": "^3.0.1",
"@parcel/watcher": "^2.3.0",
"@pothos/core": "^3.38.0",
"@pothos/plugin-dataloader": "^3.17.1",
"@pothos/plugin-relay": "^3.44.0",
"@urql/core": "^4.2.0",
"@urql/exchange-persisted": "^4.1.1",
"@urql/next": "^1.1.0",
"dataloader": "^2.2.2",
"graphql": "^16.8.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/core/rsc.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// src/next/rsc.ts
import { Exchange } from '@urql/core'
export { registerUrql as registerClient } from '@urql/next/rsc'
export * from '@urql/core'

export const persistedExchange: Exchange
8 changes: 8 additions & 0 deletions packages/core/src/next/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { useQuery, UrqlProvider } from '@urql/next'
import { persistedExchange as urqlPersistedExchange } from '@urql/exchange-persisted'

export const persistedExchange = urqlPersistedExchange({
enforcePersistedQueries: process.env.NODE_ENV === 'production',
enableForMutation: true,
generateHash: (_, document) =>
Promise.resolve((document as any)['__meta__']['hash']),
})

export * from 'urql'
export { useQuery, UrqlProvider as Provider }
Loading

0 comments on commit 76a0416

Please sign in to comment.