Skip to content

Commit

Permalink
Scope down sub-packages and merge into main package (#10)
Browse files Browse the repository at this point in the history
* add in pothos simple list

* remove CLI and such

* readme

* yeaya

* cleanup

* cleanup

* cleanup more

* produce schema.graphql

* readme
  • Loading branch information
JoviDeCroock authored Nov 29, 2023
1 parent 1136938 commit 2608923
Show file tree
Hide file tree
Showing 44 changed files with 397 additions and 1,124 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ cd dist && pnpm dev
- [x] DATASOURCES: figure out automated headers approach i.e. use `context.headers` always?
- [x] DATASOURCES: expand for mutative methods like create/update/delete
- [x] NEXT: verify whether `@fuse/next/client` works in the pages directory (It does not due to the import of `next/navigation`)
- [ ] NEXT: fix context retrieval and `require.context` usage in `next.js`
- [x] NEXT: support the `pages/` directory with a client
- [ ] WORKSPACE: merge all packages in `core` for now
- [ ] URQL: solve bug with `pages/` directory not rehydrating correctly
- [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`

## Nice to have

- [ ] CODEGEN: support custom scalars in our codegen
- [ ] SCHEMA: come up with a way to type `context` as that is part of the `SchemaBuilder`
- [ ] YOGA: way for adopting persisted-operations easily
- [ ] NEXT: produce `schema.graphql` for `GraphQLSP` so it doesn't have to rely on refetching the introspection
- [x] NEXT: produce `schema.graphql` for `GraphQLSP` so it doesn't have to rely on refetching the introspection
- [x] NEXT: figure out missing `client.d.ts` and `rsc.d.ts` in our output bundles
2 changes: 1 addition & 1 deletion examples/next/app/api/datalayer/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { datalayer } from '@fuse/next'
import { datalayer } from 'fuse/next'

const keys = require.context('../../../types', true, /\.ts$/)
keys
Expand Down
10 changes: 5 additions & 5 deletions examples/next/app/client/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import * as React from 'react'
import { useQuery } from '@fuse/next/client'

import { graphql } from '@/gql'
import { LaunchItem } from '@/components/LaunchItem'
Expand All @@ -15,7 +14,8 @@ import {
cacheExchange,
fetchExchange,
createClient,
} from '@fuse/next/client'
useQuery,
} from 'fuse/next/client'
import { useSearchParams } from 'next/navigation'

export default function Page() {
Expand Down Expand Up @@ -57,9 +57,9 @@ const LaunchesQuery = graphql(`
function Launches() {
const searchparams = useSearchParams()

const selected = searchparams.get('selected')
const offset = searchparams.has('offset')
? Number(searchparams.get('offset'))
const selected = searchparams!.get('selected')
const offset = searchparams!.has('offset')
? Number(searchparams!.get('offset'))
: 0

const [result] = useQuery({
Expand Down
2 changes: 1 addition & 1 deletion examples/next/app/rsc/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { registerUrql, createClient, fetchExchange } from '@fuse/next/rsc'
import { registerUrql, createClient, fetchExchange } from 'fuse/next/server'

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

export const DatalayerProvider = (props: any) => {
Expand Down
4 changes: 0 additions & 4 deletions examples/next/gql/persisted-documents.json

This file was deleted.

2 changes: 1 addition & 1 deletion examples/next/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { nextFusePlugin } = require('@fuse/next/plugin')
const { nextFusePlugin } = require('fuse/next/plugin')

/** @type {import('next').NextConfig} */
const nextConfig = nextFusePlugin()({})
Expand Down
1 change: 0 additions & 1 deletion examples/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "next lint"
},
"dependencies": {
"@fuse/next": "workspace:*",
"@graphql-typed-document-node/core": "^3.2.0",
"@urql/next": "^1.1.0",
"graphql": "^16.8.1",
Expand Down
10 changes: 4 additions & 6 deletions examples/next/pages/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
ssrExchange,
cacheExchange,
fetchExchange,
debugExchange,
} from '@fuse/next/pages'
} from 'fuse/next/pages'

import { graphql } from '@/gql'

Expand Down Expand Up @@ -40,7 +39,6 @@ const LaunchesQuery = graphql(`
function Launches() {
const router = useRouter()

const selected = router.query['selected']
const offset = router.query['offset'] ? Number(router.query['offset']) : 0

const [result] = useQuery({
Expand All @@ -64,10 +62,10 @@ export async function getServerSideProps() {
const ssrCache = ssrExchange({ isClient: false })
const client = initUrqlClient({
url: 'http://localhost:3000/api/datalayer',
exchanges: [cacheExchange, debugExchange, ssrCache, fetchExchange],
exchanges: [cacheExchange, ssrCache, fetchExchange],
})

await client.query(LaunchesQuery, {}).toPromise()
await client.query(LaunchesQuery, { limit: 10, offset: 0 }).toPromise()

const urqlState = ssrCache.extractData()

Expand All @@ -80,5 +78,5 @@ export async function getServerSideProps() {

export default withUrqlClient((ssrCache) => ({
url: 'http://localhost:3000/api/datalayer',
exchanges: [cacheExchange, debugExchange, ssrCache, fetchExchange],
exchanges: [cacheExchange, ssrCache, fetchExchange],
}))(Page)
62 changes: 62 additions & 0 deletions examples/next/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
A date string, such as 2007-12-03, compliant with the `full-date` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.
"""
scalar Date

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON

type Launch implements Node {
details: String
id: ID!
image: String!
launchDate: String!
name: String!
rocket: Rocket!
site: Site!
}

type Location {
latitude: Float!
longitude: Float!
name: String!
region: String!
}

type Mutation {
_version: String!
}

interface Node {
id: ID!
}

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

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

type Rocket implements Node {
company: String!
cost: Int!
country: String!
description: String!
id: ID!
}

type Site implements Node {
details: String!
id: ID!
location: Location!
name: String!
status: String!
}
2 changes: 1 addition & 1 deletion examples/next/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"name": "@0no-co/graphqlsp",
"schema": "http://localhost:3000/api/datalayer",
"schema": "./schema.graphql",
"disableTypegen": true,
"templateIsCallExpression": true,
"template": "graphql"
Expand Down
13 changes: 8 additions & 5 deletions examples/next/types/Launch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { builder, node } from 'fuse'

// The type we expect from the API
interface OutputType {
interface BackendResource {
flight_number: number
mission_name: string
launch_date_utc: string
Expand All @@ -11,7 +11,7 @@ interface OutputType {
links: { mission_patch: string }
}

export const LaunchNode = node<OutputType>({
export const LaunchNode = node<BackendResource>({
name: 'Launch',
key: 'flight_number',
async load(ids) {
Expand Down Expand Up @@ -65,9 +65,12 @@ builder.queryField('launches', (fieldBuilder) =>
])

return {
// also possible
// nodes: launches.map((x: OutputType) => x.flight_number),
nodes: launches as OutputType[],
// also possible, which will make all entities auto-resolve,
// think of cases where the API returns a limited subset of fields
// and you want to ensure you resolve with all details.
// The node.load() function will be called for each key returned.
nodes: launches.map((x: BackendResource) => x.flight_number),
//nodes: launches,
totalCount: allLaunches.length,
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fuse",
"private": true,
"scripts": {
"build": "pnpm --filter @fuse/pothos-plugin-list build && pnpm --filter fuse build && pnpm --filter @fuse/next build",
"build": "pnpm --filter fuse build",
"dev": "pnpm --filter @fuse-examples/next dev",
"prepare": "husky install"
},
Expand Down
Loading

0 comments on commit 2608923

Please sign in to comment.