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

Feat/warning inline functions #509

Merged
merged 10 commits into from
Sep 4, 2022
Merged
5 changes: 5 additions & 0 deletions .changeset/beige-cherries-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

warn users that inline functions no longer exist
223 changes: 139 additions & 84 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cmd/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
parseJS,
HoudiniError,
} from '../common'
import { getSiteUrl } from '../runtime/lib/constants'
import * as generators from './generators'
import * as transforms from './transforms'
import { CollectedGraphQLDocument, ArtifactKind } from './types'
Expand Down Expand Up @@ -159,7 +160,7 @@ export async function runPipeline(config: Config, docs: CollectedGraphQLDocument
const major = parseInt(previousVersion.split('.')[1])
if (major < 16) {
console.log(
`❓ For a description of what's changed, visit this guide: http://docs-next-kohl.vercel.app/guides/release-notes`
`❓ For a description of what's changed, visit this guide: ${getSiteUrl()}/guides/release-notes`
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/generators/definitions/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('adds internal documents to schema', async function () {

"""
@paginate is used to to mark a field for pagination.
More info in the [doc](https://www.houdinigraphql.com/guides/pagination).
More info in the [doc](https://docs-next-kohl.vercel.app/guides/pagination).
"""
directive @paginate(name: String) on FIELD

Expand Down Expand Up @@ -96,7 +96,7 @@ test('list operations are included', async function () {

"""
@paginate is used to to mark a field for pagination.
More info in the [doc](https://www.houdinigraphql.com/guides/pagination).
More info in the [doc](https://docs-next-kohl.vercel.app/guides/pagination).
"""
directive @paginate(name: String) on FIELD

Expand Down Expand Up @@ -176,7 +176,7 @@ test("writing twice doesn't duplicate definitions", async function () {

"""
@paginate is used to to mark a field for pagination.
More info in the [doc](https://www.houdinigraphql.com/guides/pagination).
More info in the [doc](https://docs-next-kohl.vercel.app/guides/pagination).
"""
directive @paginate(name: String) on FIELD

Expand Down
3 changes: 0 additions & 3 deletions src/cmd/generators/runtime/copyRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ test('updates the network file with the client path', async function () {
import { HoudiniClient } from '$houdini/runtime'

export default new HoudiniClient(fetchQuery)


For more information, please visit this link: https://www.houdinigraphql.com/guides/migrating-to-0.15.0#environment
\`);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/generators/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path'
import * as recast from 'recast'

import { Config, HoudiniError, writeFile } from '../../../common'
import { getSiteUrl } from '../../../runtime/lib/constants'
import { CollectedGraphQLDocument } from '../../types'
import { flattenSelections } from '../../utils'
import { addReferencedInputTypes } from './addReferencedInputTypes'
Expand Down Expand Up @@ -151,7 +152,7 @@ ${[...missingScalars]
}
}

For more information, please visit this link: https://www.houdinigraphql.com/api/config#custom-scalars`)
For more information, please visit this link: ${getSiteUrl()}/api/config#custom-scalars`)
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/cmd/transforms/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logGreen, logYellow } from '@kitql/helper'
import * as graphql from 'graphql'

import { Config, parentTypeFromAncestors, HoudiniError } from '../../common'
import { getSiteUrl } from '../../runtime/lib/constants'
import { ArtifactKind } from '../../runtime/lib/types'
import { CollectedGraphQLDocument } from '../types'
import { TypeWrapper, unwrapType } from '../utils'
Expand Down Expand Up @@ -449,7 +450,7 @@ const missingPaginationArgMessage = (
)} directive on a field but have not provided a ${logYellow('first')}, ${logYellow(
'last'
)}, or ${logYellow('limit')} argument. Please add one and try again.
For more information, visit this link: https://www.houdinigraphql.com/guides/pagination`
For more information, visit this link: ${getSiteUrl()}/guides/pagination`

const missingEdgeSelectionMessage = (
config: Config
Expand All @@ -458,7 +459,7 @@ const missingEdgeSelectionMessage = (
)} directive on a field but your selection does not contain an ${logYellow(
'edges'
)} field. Please add one and try again.
For more information, visit this link: https://www.houdinigraphql.com/guides/pagination`
For more information, visit this link: ${getSiteUrl()}/guides/pagination`

const missingNodeSelectionMessage = (
config: Config
Expand All @@ -467,14 +468,14 @@ const missingNodeSelectionMessage = (
)} directive on a field but your selection does not contain a ${logYellow(
'node'
)} field. Please add one and try again.
For more information, visit this link: https://www.houdinigraphql.com/guides/pagination`
For more information, visit this link: ${getSiteUrl()}/guides/pagination`

const edgeInvalidTypeMessage = (config: Config) => `Looks like you are trying to use the ${logGreen(
`@${config.paginateDirective}`
)} directive on a field but your field does not conform to the connection spec: your edges field seems strange.
For more information, visit this link: https://www.houdinigraphql.com/guides/pagination`
For more information, visit this link: ${getSiteUrl()}/guides/pagination`

const nodeNotDefinedMessage = (config: Config) => `Looks like you are trying to use the ${logGreen(
`@${config.paginateDirective}`
)} directive on a field but your field does not conform to the connection spec: your edge type does not have node as a field.
For more information, visit this link: https://www.houdinigraphql.com/guides/pagination`
For more information, visit this link: ${getSiteUrl()}/guides/pagination`
27 changes: 20 additions & 7 deletions src/cmd/transforms/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mergeSchemas } from '@graphql-tools/schema'
import * as graphql from 'graphql'

import { Config } from '../../common'
import { getSiteUrl } from '../../runtime/lib/constants'
import { CachePolicy } from '../../runtime/lib/types'
import { CollectedGraphQLDocument } from '../types'

Expand All @@ -27,7 +28,7 @@ directive @${config.listDirective}(${config.listNameArg}: String!, connection: B

"""
@${config.paginateDirective} is used to to mark a field for pagination.
More info in the [doc](https://www.houdinigraphql.com/guides/pagination).
More info in the [doc](${getSiteUrl()}/guides/pagination).
"""
directive @${config.paginateDirective}(${config.paginateNameArg}: String) on FIELD

Expand All @@ -39,23 +40,31 @@ directive @${config.listPrependDirective}(
) on FRAGMENT_SPREAD

"""
@${config.listAppendDirective} is used to tell the runtime to add the result to the start of the list
@${
config.listAppendDirective
} is used to tell the runtime to add the result to the start of the list
"""
directive @${config.listAppendDirective}(${config.listDirectiveParentIDArg}: ID) on FRAGMENT_SPREAD

"""
@${config.listParentDirective} is used to provide a parentID without specifying position or in situations
@${
config.listParentDirective
} is used to provide a parentID without specifying position or in situations
where it doesn't make sense (eg when deleting a node.)
"""
directive @${config.listParentDirective}(value: ID!) on FRAGMENT_SPREAD

"""
@${config.whenDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
@${
config.whenDirective
} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
"""
directive @${config.whenDirective} on FRAGMENT_SPREAD

"""
@${config.whenNotDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
@${
config.whenNotDirective
} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
"""
directive @${config.whenNotDirective} on FRAGMENT_SPREAD

Expand All @@ -67,10 +76,14 @@ directive @${config.argumentsDirective} on FRAGMENT_DEFINITION
"""
@${config.cacheDirective} is used to specify cache rules for a query
"""
directive @${config.cacheDirective}(${config.cachePolicyArg}: CachePolicy, ${config.cachePartialArg}: Boolean) on QUERY
directive @${config.cacheDirective}(${config.cachePolicyArg}: CachePolicy, ${
config.cachePartialArg
}: Boolean) on QUERY

"""
@${config.houdiniDirective} is used to configure houdini's internal behavior such as opting-in an automatic load
@${
config.houdiniDirective
} is used to configure houdini's internal behavior such as opting-in an automatic load
"""
directive @${config.houdiniDirective}(load: Boolean = true) on QUERY
`
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/validators/typeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
parentTypeFromAncestors,
HoudiniError,
} from '../../common'
import { getSiteUrl } from '../../runtime/lib/constants'
import {
FragmentArgument,
fragmentArguments as collectFragmentArguments,
Expand Down Expand Up @@ -1017,7 +1018,7 @@ extend type Query {

For more information, please visit these links:
- https://graphql.org/learn/global-object-identification/
- https://www.houdinigraphql.com/guides/caching-data#custom-ids
- ${getSiteUrl()}/guides/caching-data#custom-ids
`

const paginateOnNonNodeMessage = (config: Config, directiveName: string) =>
Expand All @@ -1026,6 +1027,6 @@ If this is happening inside of a fragment, make sure that the fragment either im
have defined a resolver entry for the fragment type.

For more information, please visit these links:
- https://www.houdinigraphql.com/guides/pagination#paginated-fragments
- https://www.houdinigraphql.com/guides/caching-data#custom-ids
- ${getSiteUrl()}/guides/pagination#paginated-fragments
- ${getSiteUrl()}/guides/caching-data#custom-ids
`
3 changes: 2 additions & 1 deletion src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getSiteUrl } from './lib/constants'
import { GraphQLTagResult } from './lib/types'

export * from './lib'
Expand All @@ -22,6 +23,6 @@ export function graphql(str: TemplateStringsArray): any {
// if this is executed, the preprocessor is not enabled
throw new Error(`⚠️ graphql template was invoked at runtime. This should never happen and usually means that your project isn't properly configured.

Please make sure you have the appropriate plugin/preprocessor enabled. For more information, visit this link: https://www.houdinigraphql.com/guides/setting-up-your-project
Please make sure you have the appropriate plugin/preprocessor enabled. For more information, visit this link: ${getSiteUrl()}/guides/setting-up-your-project
`)
}
3 changes: 3 additions & 0 deletions src/runtime/inline/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { fragment, paginatedFragment } from './fragment'
export { query, paginatedQuery } from './query'
export { mutation } from './mutation'
export { subscription } from './subscription'
15 changes: 15 additions & 0 deletions src/runtime/inline/mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HoudiniRTError } from '../lib/HoudiniRTError'
import { InfoReleaseNote, OutdatedFunctionInlineInfo } from '../lib/constants'
import { GraphQLTagResult, Operation } from '../lib/index'

export function mutation<_Mutation extends Operation<any, any>>(store: GraphQLTagResult) {
// no longer exist!
throw new HoudiniRTError('mutation', {
type: 'OutdatedFunction',
extraInfo: [
OutdatedFunctionInlineInfo('mutation', store.artifact.name),
InfoReleaseNote('#0160'),
],
quiet: true,
})
}
28 changes: 28 additions & 0 deletions src/runtime/inline/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { HoudiniRTError } from '../lib/HoudiniRTError'
import { getSiteUrl, InfoReleaseNote, OutdatedFunctionInlineInfo } from '../lib/constants'
import { GraphQLTagResult, Operation } from '../lib/types'

export function query<_Query extends Operation<any, any>>(store: GraphQLTagResult) {
// no longer exist!
throw new HoudiniRTError('query', {
type: 'OutdatedFunction',

extraInfo: [
OutdatedFunctionInlineInfo('query', store.artifact.name),
InfoReleaseNote('#0160'),
],
quiet: true,
})
}

export function paginatedQuery<_Query extends Operation<any, any>>(store: GraphQLTagResult) {
// no longer exist!
throw new HoudiniRTError('paginatedQuery', {
type: 'OutdatedFunction',
extraInfo: [
OutdatedFunctionInlineInfo('paginatedQuery', store.artifact.name),
InfoReleaseNote('#0160'),
],
quiet: true,
})
}
18 changes: 18 additions & 0 deletions src/runtime/inline/subscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HoudiniRTError } from '../lib/HoudiniRTError'
import { InfoReleaseNote, OutdatedFunctionInlineInfo } from '../lib/constants'
import { GraphQLTagResult, Operation } from '../lib/types'

export function subscription<_Subscription extends Operation<any, any>>(
store: GraphQLTagResult,
variables?: _Subscription['input']
) {
// no longer exist!
throw new HoudiniRTError('subscription', {
type: 'OutdatedFunction',
extraInfo: [
OutdatedFunctionInlineInfo('subscription', store.artifact.name),
InfoReleaseNote('#0160'),
],
quiet: true,
})
}
29 changes: 29 additions & 0 deletions src/runtime/lib/HoudiniRTError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export type RTErrorType = 'default' | 'OutdatedFunction'

// Houdini Runtime Error (something light-weighted)
export class HoudiniRTError extends Error {
constructor(
message: string,
{
type = 'default',
extraInfo = [],
quiet = false,
}: {
type?: RTErrorType
extraInfo?: string[]
quiet?: boolean
}
) {
// log extra info before throwing error
extraInfo?.forEach((line) => {
console.log(line)
})

super(type === 'OutdatedFunction' ? `Outdated function "${message}"` : message)

// if quiet, don't log the stack trace
if (quiet) {
this.stack = ''
}
}
}
25 changes: 25 additions & 0 deletions src/runtime/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const getSiteUrl = () => {
// Now, manual return
// TESTS Snapshots needs to be updated as well when changing this.
const next_url = 'https://docs-next-kohl.vercel.app'
return next_url

// const current_url = 'https://www.houdinigraphql.com'
// return next_url
}

/**
* @param focus example "#0160"
*/
export const InfoReleaseNote = (focus?: string) => {
return `❓ For more info, visit this guide: ${getSiteUrl()}/guides/release-notes${
focus ? `${focus}` : ''
}`
}

export const OutdatedFunctionInlineInfo = (
type: 'query' | 'paginatedQuery' | 'mutation' | 'subscription',
name: string
) => {
return `❌ inline function "${type}" no longer exist (update: '${name}' ${type}).`
}
4 changes: 1 addition & 3 deletions src/runtime/lib/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { get } from 'svelte/store'
import cache from '../cache'
import { QueryResult } from '../stores/query'
import type { ConfigFile } from './config'
import { getSiteUrl } from './constants'
import * as log from './log'
import { marshalInputs } from './scalars'
import {
Expand Down Expand Up @@ -66,9 +67,6 @@ You should update your client to look something like the following:
import { HoudiniClient } from '$houdini/runtime'

export default new HoudiniClient(fetchQuery)


For more information, please visit this link: https://www.houdinigraphql.com/guides/migrating-to-0.15.0#environment
`
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/stores/pagination/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Writable, writable } from 'svelte/store'

import cache from '../../cache'
import { ConfigFile } from '../../lib/config'
import { getSiteUrl } from '../../lib/constants'
import { deepEquals } from '../../lib/deepEquals'
import { executeQuery } from '../../lib/network'
import { GraphQLObject, QueryArtifact } from '../../lib/types'
Expand Down Expand Up @@ -77,7 +78,7 @@ export function cursorHandlers<_Data extends GraphQLObject, _Input>({
// make sure we have a type config for the pagination target type
if (!config.types?.[targetType]?.resolve) {
throw new Error(
`Missing type resolve configuration for ${targetType}. For more information, see https://www.houdinigraphql.com/guides/pagination#paginated-fragments`
`Missing type resolve configuration for ${targetType}. For more information, see ${getSiteUrl()}/guides/pagination#paginated-fragments`
)
}

Expand Down
Loading