Skip to content

Commit

Permalink
address issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jan 16, 2024
1 parent 76fe38b commit e9ee558
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 210 deletions.
2 changes: 1 addition & 1 deletion examples/ecommerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-dom": "^18"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.0.0",
"@0no-co/graphqlsp": "^1.0.1",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
2 changes: 1 addition & 1 deletion examples/spacex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-dom": "^18"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.0.0",
"@0no-co/graphqlsp": "^1.0.1",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
4 changes: 2 additions & 2 deletions examples/standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"build": "vite build && fuse build"
},
"dependencies": {
"gql.tada": "^1.0.0",
"gql.tada": "1.0.1-canary-7986c5421362da3ff161beb2a2ed90c51fa04b27",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.0.0",
"@0no-co/graphqlsp": "^1.0.1",
"@graphql-typed-document-node/core": "^3.2.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
Expand Down
1 change: 0 additions & 1 deletion examples/standalone/src/components/LaunchItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const LaunchItem = (props: {
select: () => void
}) => {
const node = readFragment(LaunchFields, props.launch)

return (
<li className={styles.item} onClick={props.select}>
<img className={styles.badge} src={node.image} alt={node.name} />
Expand Down
85 changes: 0 additions & 85 deletions examples/standalone/src/fuse/fragment-masking.ts

This file was deleted.

86 changes: 0 additions & 86 deletions examples/standalone/src/fuse/gql.ts

This file was deleted.

1 change: 0 additions & 1 deletion examples/standalone/src/fuse/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './fragment-masking'
export * from './graphql'
export * from 'fuse/client'
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"graphql": "^16.8.1",
"graphql-scalars": "^1.22.4",
"graphql-yoga": "^5.0.0",
"gql.tada": "^1.0.0",
"sade": "^1.8.1",
"stellate": "^2.7.1",
"urql": "^4.0.6",
Expand Down
80 changes: 64 additions & 16 deletions packages/core/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import path from 'path'
import fs, { writeFile, appendFile } from 'fs/promises'
import { createServer, build } from 'vite'
import { VitePluginNode } from 'vite-plugin-node'
import { generate, CodegenContext } from '@graphql-codegen/cli'
import { DateTimeResolver, JSONResolver } from 'graphql-scalars'
import { existsSync } from 'fs'

const prog = sade('fuse')

prog.version('0.0.0')
prog.version(process.env.npm_package_version ?? '0.0.0')

prog
.command('build')
Expand Down Expand Up @@ -89,14 +91,8 @@ prog
}

if (opts.client) {
const baseDirectory = process.cwd()
const hasSrcDir = existsSync(path.resolve(baseDirectory, 'src'))
await appendFile(
hasSrcDir
? baseDirectory + 'src/fuse/index.ts'
: baseDirectory + '/fuse' + '/index.ts',
'\nexport * from "fuse/client"',
)
// TODO: bail out when the user is using gql.tada
await boostrapCodegen(opts.schema, false)
}
})
.command('dev')
Expand Down Expand Up @@ -168,14 +164,66 @@ prog
}

if (opts.client) {
const hasSrcDir = existsSync(path.resolve(baseDirectory, 'src'))
await appendFile(
hasSrcDir
? baseDirectory + 'src/fuse/index.ts'
: baseDirectory + '/fuse' + '/index.ts',
'\nexport * from "fuse/client"',
)
// TODO: bail out when the user is using gql.tada
await boostrapCodegen(opts.schema, true)
}
})

prog.parse(process.argv)

async function boostrapCodegen(location: string, watch: boolean) {
const baseDirectory = process.cwd()
const hasSrcDir = existsSync(path.resolve(baseDirectory, 'src'))

const ctx = new CodegenContext({
filepath: 'codgen.yml',
config: {
ignoreNoDocuments: true,
errorsOnly: true,
noSilentErrors: true,
watch: watch
? [
hasSrcDir
? baseDirectory + '/src/**/*.{ts,tsx}'
: baseDirectory + '/**/*.{ts,tsx}',
]
: false,
schema: location,
generates: {
[hasSrcDir ? baseDirectory + '/src/fuse/' : baseDirectory + '/fuse/']: {
documents: [
hasSrcDir ? './src/**/*.{ts,tsx}' : './**/*.{ts,tsx}',
'!./{node_modules,.next,.git}/**/*',
],
preset: 'client',
// presetConfig: {
// persistedDocuments: true,
// },
config: {
scalars: {
ID: {
input: 'string',
output: 'string',
},
DateTime: DateTimeResolver.extensions.codegenScalarType,
JSON: JSONResolver.extensions.codegenScalarType,
},
avoidOptionals: false,
enumsAsTypes: true,
nonOptionalTypename: true,
skipTypename: false,
},
},
},
},
})

await generate(ctx, true)

await appendFile(
hasSrcDir
? baseDirectory + '/src/fuse/index.ts'
: baseDirectory + '/fuse/index.ts',
'\nexport * from "fuse/client"',
)
}
Loading

0 comments on commit e9ee558

Please sign in to comment.