Skip to content

Commit

Permalink
fix(standalone): respect src dir (#120)
Browse files Browse the repository at this point in the history
* respect src dir when appending files

* fixes

* remove logs
  • Loading branch information
JoviDeCroock authored Jan 16, 2024
1 parent 08b521f commit cc58565
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 57 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-doors-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fuse': patch
---

Fix src dir with appended file
2 changes: 1 addition & 1 deletion examples/standalone/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'

import { graphql, useQuery } from '../fuse'
import { graphql, useQuery } from './fuse'
import { LaunchItem } from './components/LaunchItem'
import { PageNumbers } from './components/PageNumbers'
import { LaunchDetails } from './components/LaunchDetails'
Expand Down
9 changes: 1 addition & 8 deletions examples/standalone/src/components/LaunchDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphql, useQuery } from '../../fuse'
import { graphql, useQuery } from '../fuse'
import { LaunchSite } from './LaunchSite'

const LaunchDetailsQuery = graphql(`
Expand All @@ -9,16 +9,9 @@ const LaunchDetailsQuery = graphql(`
name
details
launchDate
image
site {
...LaunchSiteFields
}
rocket {
cost
country
company
description
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/src/components/LaunchItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FragmentType, graphql, useFragment } from '../../fuse'
import { FragmentType, graphql, useFragment } from '../fuse'
import styles from './LaunchItem.module.css'

const LaunchFields = graphql(`
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/src/components/LaunchSite.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FragmentType, graphql, useFragment } from '../../fuse'
import { FragmentType, graphql, useFragment } from '../fuse'
import { Location } from './Location'

const LaunchSiteFields = graphql(`
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/src/components/Location.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FragmentType, graphql, useFragment } from '../../fuse'
import { FragmentType, graphql, useFragment } from '../fuse'

const SiteLocationFields = graphql(`
fragment SiteLocationFields on Location {
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/src/components/PageNumbers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FragmentType, graphql, useFragment } from '../../fuse'
import { FragmentType, graphql, useFragment } from '../fuse'

import styles from './PageNumbers.module.css'

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
const documents = {
'\n query Launches_SSR($limit: Int, $offset: Int) {\n launches(limit: $limit, offset: $offset) {\n nodes {\n id\n ...LaunchFields\n }\n ...TotalCountFields\n }\n }\n':
types.Launches_SsrDocument,
'\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n image\n site {\n ...LaunchSiteFields\n }\n rocket {\n cost\n country\n company\n description\n }\n }\n }\n }\n':
'\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n site {\n ...LaunchSiteFields\n }\n }\n }\n }\n':
types.LaunchDetailsDocument,
'\n fragment LaunchFields on Launch {\n name\n launchDate\n image\n }\n':
types.LaunchFieldsFragmentDoc,
Expand Down Expand Up @@ -51,8 +51,8 @@ export function graphql(
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n image\n site {\n ...LaunchSiteFields\n }\n rocket {\n cost\n country\n company\n description\n }\n }\n }\n }\n',
): (typeof documents)['\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n image\n site {\n ...LaunchSiteFields\n }\n rocket {\n cost\n country\n company\n description\n }\n }\n }\n }\n']
source: '\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n site {\n ...LaunchSiteFields\n }\n }\n }\n }\n',
): (typeof documents)['\n query LaunchDetails($id: ID!) {\n node(id: $id) {\n ... on Launch {\n id\n name\n details\n launchDate\n site {\n ...LaunchSiteFields\n }\n }\n }\n }\n']
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,11 @@ export type LaunchDetailsQuery = {
name: string
details?: string | null
launchDate: string
image: string
site: { __typename: 'Site' } & {
' $fragmentRefs'?: {
LaunchSiteFieldsFragment: LaunchSiteFieldsFragment
}
}
rocket: {
__typename: 'Rocket'
cost?: number | null
country?: string | null
company?: string | null
description?: string | null
}
}
| { __typename: 'Rocket' }
| { __typename: 'Site' }
Expand Down Expand Up @@ -493,7 +485,6 @@ export const LaunchDetailsDocument = {
kind: 'Field',
name: { kind: 'Name', value: 'launchDate' },
},
{ kind: 'Field', name: { kind: 'Name', value: 'image' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'site' },
Expand All @@ -507,31 +498,6 @@ export const LaunchDetailsDocument = {
],
},
},
{
kind: 'Field',
name: { kind: 'Name', value: 'rocket' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'cost' },
},
{
kind: 'Field',
name: { kind: 'Name', value: 'country' },
},
{
kind: 'Field',
name: { kind: 'Name', value: 'company' },
},
{
kind: 'Field',
name: { kind: 'Name', value: 'description' },
},
],
},
},
],
},
},
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/standalone/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { createClient, Provider } from '../fuse'
import { createClient, Provider } from './fuse'
import App from './App.tsx'
import './index.css'

Expand Down
23 changes: 17 additions & 6 deletions packages/core/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import sade from 'sade'
import path from 'path'
import fs, { appendFile } from 'fs/promises'
import fs, { writeFile } from 'fs/promises'
import { createServer, build } from 'vite'
import { VitePluginNode } from 'vite-plugin-node'
import { generate, CodegenContext } from '@graphql-codegen/cli'
Expand Down Expand Up @@ -173,17 +173,32 @@ async function boostrapCodegen(location: string, watch: boolean) {
const baseDirectory = process.cwd()
const hasSrcDir = existsSync(path.resolve(baseDirectory, 'src'))

const contents = `export * from "./fragment-masking";
export * from "./gql";
export * from "fuse/client";\n`
const ctx = new CodegenContext({
filepath: 'codgen.yml',
config: {
ignoreNoDocuments: true,
errorsOnly: true,
noSilentErrors: true,
hooks: {
afterOneFileWrite: async () => {
await writeFile(
hasSrcDir
? baseDirectory + '/src/fuse/index.ts'
: baseDirectory + '/fuse/index.ts',
contents,
)
},
},
watch: watch
? [
hasSrcDir
? baseDirectory + '/src/**/*.{ts,tsx}'
: baseDirectory + '/**/*.{ts,tsx}',
'!./{node_modules,.next,.git}/**/*',
hasSrcDir ? '!./src/fuse/*.{ts,tsx}' : '!./fuse/*.{ts,tsx}',
]
: false,
schema: location,
Expand All @@ -192,6 +207,7 @@ async function boostrapCodegen(location: string, watch: boolean) {
documents: [
hasSrcDir ? './src/**/*.{ts,tsx}' : './**/*.{ts,tsx}',
'!./{node_modules,.next,.git}/**/*',
hasSrcDir ? '!./src/fuse/*.{ts,tsx}' : '!./fuse/*.{ts,tsx}',
],
preset: 'client',
// presetConfig: {
Expand All @@ -217,9 +233,4 @@ async function boostrapCodegen(location: string, watch: boolean) {
})

await generate(ctx, true)

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

1 comment on commit cc58565

@vercel
Copy link

@vercel vercel bot commented on cc58565 Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

spacex-fuse – ./examples/spacex

spacex-fuse-git-main-stellate.vercel.app
spacex-fuse-stellate.vercel.app
spacex-fuse.vercel.app

Please sign in to comment.