Skip to content

Commit

Permalink
✨ NEW: useKitModules (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Oct 21, 2022
1 parent 8653601 commit 63e40d2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-cheetahs-wink.md
@@ -0,0 +1,5 @@
---
'@kitql/all-in': patch
---

add useKitModules middlewares & providers
4 changes: 4 additions & 0 deletions packages/all-in/src/lib/cjs.cjs
Expand Up @@ -3,6 +3,9 @@ function kitQLCodegen(projectLocation, scalars) {
generates: {
[`${projectLocation}src/lib/graphql/$kitql/graphqlTypes.ts`]: {
plugins: ['typescript', 'typescript-resolvers'],
config: {
scalars,
},
},
[`${projectLocation}src/lib/modules/`]: {
preset: 'graphql-modules',
Expand All @@ -21,6 +24,7 @@ function kitQLCodegen(projectLocation, scalars) {
},
config: {
useTypeImports: true,
enumsAsTypes: true,
},
}
}
Expand Down
14 changes: 0 additions & 14 deletions packages/all-in/src/lib/graphql/kitQLModules.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/all-in/src/lib/graphql/kitQLServer.ts
Expand Up @@ -2,10 +2,10 @@ import type { KitQLHandleGraphQL } from '$lib/hooks/graphql'
import type { RequestEvent } from '@sveltejs/kit'

import { modules } from './$kitql/_appModules'
import { kitQLModules } from './kitQLModules.js'
import { useKitModules } from './useKitModules.js'

const plugins = []
plugins.push(kitQLModules(modules))
plugins.push(useKitModules(modules))

function getContext({ request }: RequestEvent) {
// get the cookie or the token...
Expand Down
21 changes: 21 additions & 0 deletions packages/all-in/src/lib/graphql/useKitModules.ts
@@ -0,0 +1,21 @@
import { useGraphQLModules } from '@envelop/graphql-modules'
import { createApplication, type Module, type Provider } from 'graphql-modules'
import type { MiddlewareMap } from 'graphql-modules/shared/middleware'

export const useKitModules = (
modules: Module[],
middlewares?: MiddlewareMap,
providers?: Provider<any>[] | (() => Provider<any>[])
) => {
try {
return useGraphQLModules(
createApplication({
modules,
middlewares,
providers,
})
)
} catch (error) {
console.error(error)
}
}
7 changes: 4 additions & 3 deletions packages/all-in/src/lib/index.ts
Expand Up @@ -2,8 +2,8 @@
// export { default as KitQLInfo } from './KitQLInfo.svelte'

// graphql-modules
export { createModule } from 'graphql-modules'
export { kitQLModules } from './graphql/kitQLModules.js'
export { createModule as kitQLModules } from 'graphql-modules'
export { useKitModules } from './graphql/useKitModules.js'

// SvelteKit hooks
export { type KitQLHandleGraphQL, handleGraphql } from './hooks/graphql.js'
Expand All @@ -15,10 +15,11 @@ export { type KitQLHandleGraphiQL, handleGraphiql } from './hooks/graphiql.js'
// GraphQL Config
export type { CodegenConfig as KitQLCodegenConfig } from '@graphql-codegen/cli'
export type { IGraphQLProject as KitQLProject } from 'graphql-config'
export { type KitQLProjects, type KitQLConfig, type KitQLScalar } from './graphql/graphqlConfig.js'
export type { KitQLProjects, KitQLConfig, KitQLScalar } from './graphql/graphqlConfig.js'

// GraphQL Helper
export { rootFields } from './graphql/helper.js'

// vite plugin
export { kitql } from './vite/plugin.js'
export type { KitQLVite } from './vite/KitQLVite.js'
4 changes: 4 additions & 0 deletions packages/all-in/svelte.config.js
Expand Up @@ -17,6 +17,10 @@ const config = {

package: {
dir: 'dist',
exports: file => {
const list_ok = ['index.ts', 'cjs.cjs']
return list_ok.includes(file)
},
},
}

Expand Down

1 comment on commit 63e40d2

@vercel
Copy link

@vercel vercel bot commented on 63e40d2 Oct 21, 2022

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:

kitql – ./

kitql-git-main-jycouet.vercel.app
kitql.vercel.app
kitql.dev
kitql-jycouet.vercel.app
www.kitql.dev

Please sign in to comment.