Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/warn on server not here #540

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-bags-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

enhancement - Warn users when endpoint is not present in dev
9 changes: 4 additions & 5 deletions src/cmd/utils/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function pullSchema(
url: string,
schemaPath: string,
headers?: Record<string, string>
) {
): Promise<boolean> {
try {
// send the request
const resp = await fetch(url, {
Expand All @@ -31,10 +31,9 @@ export async function pullSchema(
await writeFile(schemaPath, JSON.stringify(jsonSchema))
}

// return the schema for usage in --pull-schema
return schema
return true
} catch (e) {
console.log(`❌ Encountered error when pulling your latest schema: ` + (e as Error).message)
process.exit(0)
console.warn(`⚠️ Couldn't pull your latest schema: ` + (e as Error).message)
}
return false
}
7 changes: 5 additions & 2 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ export async function getConfig({

// look up the schema if we need to
if (_config.schemaPath && !_config.schema) {
let schemaOk = true
// we might have to pull the schema first
if (_config.apiUrl) {
// make sure we don't have a pattern pointing to multiple files and a remove URL
Expand All @@ -937,12 +938,14 @@ This will prevent your schema from being pulled (potentially resulting in errors
// we might have to create the file
else if (!(await fs.readFile(_config.schemaPath))) {
console.log('⌛ Pulling schema from api')
await pullSchema(_config.apiUrl, _config.schemaPath)
schemaOk = await pullSchema(_config.apiUrl, _config.schemaPath)
}
}

// the schema is safe to load
_config.schema = await loadSchemaFile(_config.schemaPath)
if (schemaOk) {
_config.schema = await loadSchemaFile(_config.schemaPath)
}
}
} catch (e) {
reject(e)
Expand Down
18 changes: 12 additions & 6 deletions src/vite/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function HoudiniWatchSchemaPlugin(configFile?: string): Plugin {
apply: 'serve',
async buildStart() {
const config = await getConfig({ configFile })
let nbPullError = 0

// validate the config

Expand All @@ -33,25 +34,30 @@ export default function HoudiniWatchSchemaPlugin(configFile?: string): Plugin {
if (interval === null) {
return
}

// the function to call on the appropriate interval
async function pull(poll: boolean) {
async function pull(more: boolean) {
try {
// Write the schema
await pullSchema(
const schemaState = await pullSchema(
config.apiUrl!,
config.schemaPath ?? path.resolve(process.cwd(), 'schema.json'),
config.pullHeaders
)

nbPullError = schemaState ? 0 : nbPullError + 1
} catch (e) {
formatErrors(e)
}

// if we are supposed to poll, wait the appropriate amount of time and then do it again
if (poll) {
await sleep(interval!)
// if we are supposed to poll more, wait the appropriate amount of time and then do it again
if (more) {
// Wait more and more and more...
const timeToWait = interval! + interval! * nbPullError
await sleep(timeToWait)

if (go) {
pull(poll)
pull(more)
}
}
}
Expand Down