Skip to content

Commit

Permalink
some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 29, 2023
1 parent bbe9c23 commit f5da97a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cd dist && pnpm dev
- [x] WORKSPACE: merge all packages in `core` for now
- [x] URQL: solve bug with `pages/` directory not rehydrating correctly
- [ ] NEXT: fix context retrieval and `require.context` usage in `next.js`
- [ ] NEXT: Try `require.context` in `node_modules`/`virtual module` again

## Nice to have

Expand Down
34 changes: 7 additions & 27 deletions examples/next/app/client/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,17 @@ import { LaunchDetails } from '@/components/LaunchDetails'
import styles from './page.module.css'
import { PageNumbers } from '@/components/PageNumbers'

import {
Provider,
ssrExchange,
cacheExchange,
fetchExchange,
createClient,
useQuery,
} from 'fuse/next/client'
import { useQuery } from 'fuse/next/client'
import { useSearchParams } from 'next/navigation'

export default function Page() {
const [client, ssr] = React.useMemo(() => {
const ssr = ssrExchange()
const client = createClient({
url: 'http://localhost:3000/api/datalayer',
exchanges: [cacheExchange, ssr, fetchExchange],
suspense: true,
})

return [client, ssr]
}, [])

return (
<Provider client={client} ssr={ssr}>
<main className={styles.main}>
<h1>SpaceX Launches</h1>
<React.Suspense fallback={<p>Loading launches...</p>}>
<Launches />
</React.Suspense>
</main>
</Provider>
<main className={styles.main}>
<h1>SpaceX Launches</h1>
<React.Suspense fallback={<p>Loading launches...</p>}>
<Launches />
</React.Suspense>
</main>
)
}

Expand Down
16 changes: 16 additions & 0 deletions examples/next/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export type Node = {
id: Scalars['ID']['output']
}

export type Pokemon = Node & {
__typename: 'Pokemon'
experience: Scalars['Int']['output']
height: Scalars['Int']['output']
id: Scalars['ID']['output']
name: Scalars['String']['output']
weight: Scalars['Int']['output']
}

export type Query = {
__typename: 'Query'
_version: Scalars['String']['output']
Expand Down Expand Up @@ -108,6 +117,12 @@ export type Site = Node & {
status: Scalars['String']['output']
}

export type Stats = {
__typename: 'Stats'
baseStat: Scalars['Int']['output']
name: Scalars['String']['output']
}

export type LaunchesQueryVariables = Exact<{
limit?: InputMaybe<Scalars['Int']['input']>
offset?: InputMaybe<Scalars['Int']['input']>
Expand Down Expand Up @@ -155,6 +170,7 @@ export type LaunchDetailsQuery = {
description: string
}
}
| { __typename: 'Pokemon' }
| { __typename: 'Rocket' }
| { __typename: 'Site' }
| null
Expand Down
19 changes: 19 additions & 0 deletions examples/next/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,32 @@ interface Node {
id: ID!
}

type Pokemon implements Node {
experience: Int!
height: Int!
id: ID!
name: String!
weight: Int!
}

type Query {
_version: String!
launches(limit: Int, offset: Int): QueryLaunchesList!
node(id: ID!): Node
nodes(ids: [ID!]!): [Node]!
pokemons: QueryPokemonsList!
}

type QueryLaunchesList {
nodes: [Launch]!
totalCount: Int
}

type QueryPokemonsList {
nodes: [Pokemon]!
totalCount: Int
}

type Rocket implements Node {
company: String!
cost: Int!
Expand All @@ -60,3 +74,8 @@ type Site implements Node {
name: String!
status: String!
}

type Stats {
baseStat: Int!
name: String!
}
17 changes: 11 additions & 6 deletions packages/core/src/next/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import { generate, CodegenContext } from '@graphql-codegen/cli'

interface Options {
port?: number
path?: string
}

export function nextFusePlugin(options: Options = {}) {
let isRunningCodegen = false
return (config?: any): any => {
if (process.env.NODE_ENV === 'development' && !isRunningCodegen) {
isRunningCodegen = true
setTimeout(() => {
boostrapCodegen(options.port || 3000)
}, 1000)
try {
isRunningCodegen = true
setTimeout(() => {
try {
boostrapCodegen(options.port || 3000, options.path || 'datalayer')
} catch (e) {}
}, 1000)
} catch (e) {}
}
return config
}
}
async function boostrapCodegen(port: number) {
async function boostrapCodegen(port: number, path: string) {
const baseDirectory = process.cwd()
const ctx = new CodegenContext({
filepath: 'codgen.yml',
Expand All @@ -28,7 +33,7 @@ async function boostrapCodegen(port: number) {
errorsOnly: true,
noSilentErrors: true,
watch: baseDirectory + '/**/*.tsx',
schema: `http://localhost:${port}/api/datalayer`,
schema: `http://localhost:${port}/api/${path}`,
documents: './**/*.tsx',
generates: {
[baseDirectory + '/gql/']: {
Expand Down

0 comments on commit f5da97a

Please sign in to comment.