Skip to content

Commit

Permalink
Allow users to specify the output path when pulling a schema (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis authored Jul 7, 2024
1 parent a31042b commit ba4be40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-dogs-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Add -o argument to pull-schema for specifying the file path
1 change: 1 addition & 0 deletions packages/houdini/src/cmd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ program
.command('pull-schema')
.usage('[options]')
.description('pull the latest schema from your api')
.option('-o, --output [outputPath]', 'the destination for the schema contents')
.option(
'-h, --headers <headers...>',
'headers to use when pulling your schema. Should be passed as KEY=VALUE'
Expand Down
12 changes: 7 additions & 5 deletions packages/houdini/src/cmd/pullSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getConfig, pullSchema, path } from '../lib'

export default async function (args: { headers: string[] }) {
export default async function (args: { headers: string[]; output?: string }) {
const config = await getConfig({ noSchema: true })
const apiURL = await config.apiURL()
// Check if apiUrl is set in config
Expand All @@ -12,9 +12,6 @@ export default async function (args: { headers: string[] }) {
return
}

// The target path -> current working directory by default. Should we allow passing custom paths?
const targetPath = process.cwd()

let headers = await config.pullHeaders()
let headerStrings: string[] = []

Expand All @@ -31,6 +28,11 @@ export default async function (args: { headers: string[] }) {
}, headers)
}

// the destination for the schema can come from the cli arguments, the config file, or a default
const targetPath = args.output
? path.resolve(args.output)
: config.schemaPath ?? path.resolve(process.cwd(), 'schema.json')

// Write the schema
await pullSchema(apiURL, config.schemaPath ?? path.resolve(targetPath, 'schema.json'), headers)
await pullSchema(apiURL, targetPath, headers)
}

0 comments on commit ba4be40

Please sign in to comment.