Skip to content

Commit

Permalink
🚸 FIX: context
Browse files Browse the repository at this point in the history
* 🎨 UPDATE: format

* 🚸 FIX: context

* 🎨 UPDATE: changeset
  • Loading branch information
jycouet committed Oct 19, 2022
1 parent d53f4af commit f2596b1
Show file tree
Hide file tree
Showing 46 changed files with 195 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-roses-itch.md
@@ -0,0 +1,5 @@
---
'@kitql/all-in': patch
---

export all the lib in svelte esm
4 changes: 3 additions & 1 deletion .prettierrc.cjs
Expand Up @@ -3,5 +3,7 @@ const { plugins, ...prettierConfig } = require('@theguild/prettier-config')
module.exports = {
...prettierConfig,
semi: false,
plugins: [...plugins, 'prettier-plugin-svelte'],
plugins: [...plugins, 'prettier-plugin-svelte', '@trivago/prettier-plugin-sort-imports'],
importOrder: ['<THIRD_PARTY_MODULES>', '^[./]'],
importOrderSeparation: true,
}
7 changes: 2 additions & 5 deletions examples/demo-init/package.json
Expand Up @@ -8,6 +8,7 @@
"url": "https://github.com/jycouet/kitql",
"directory": "examples/demo-init"
},
"type": "module",
"scripts": {
"dev": "vite dev --port 3777",
"build": "npm run build:date && vite build",
Expand Down Expand Up @@ -38,14 +39,10 @@
"vite": "3.1.7"
},
"dependencies": {
"@kitql/all-in": "0.8.0-next.6",
"@kitql/all-in": "0.8.0-next.7",
"houdini": "0.16.8",
"graphql": "15.5.3"
},
"resolutions": {
"graphql": "15.5.3"
},
"type": "module",
"engines": {
"node": ">=16.0.0"
},
Expand Down
8 changes: 4 additions & 4 deletions examples/demo-init/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"@changesets/cli": "2.24.4",
"@theguild/eslint-config": "0.0.2",
"@theguild/prettier-config": "0.0.3",
"@trivago/prettier-plugin-sort-imports": "^3.3.1",
"@vitest/coverage-c8": "^0.24.3",
"@vitest/ui": "0.23.2",
"bob-the-bundler": "4.0.0",
Expand Down
12 changes: 7 additions & 5 deletions packages/all-in/src/lib/graphql/kitQLServer.ts
@@ -1,6 +1,8 @@
import type { KitQLHandleGraphQL } from '$lib/hooks/graphql'
import type { RequestEvent } from '@sveltejs/kit'

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

const plugins = []
plugins.push(kitQLModules(modules))
Expand All @@ -9,8 +11,8 @@ function getContext({ request }: RequestEvent) {
// get the cookie or the token...
const coolInfo = request.headers.get('Authorization')

// get the user from the coolInfo (redis or db)
const user = { id: 1, name: 'John' }
// get the user from the coolInfo (redis or db or ...)
const user = { id: 7, name: 'JYC' }

return {
request,
Expand All @@ -33,7 +35,7 @@ export type IKitQLContext = ReturnType<typeof getContext>
// config:
// contextType: $graphql/kitQLServer#IKitQLContext

export const kitqlServer = {
export const kitqlServer: KitQLHandleGraphQL<IKitQLContext> = {
plugins,
getContext,
context: getContext,
}
1 change: 1 addition & 0 deletions packages/all-in/src/lib/hooks/graphql.ts
Expand Up @@ -51,6 +51,7 @@ export function handleGraphql<TUserContext>(options?: KitQLHandleGraphQL<TUserCo

const kitqlServer = createYoga<YogaInitialContext, TUserContext>({
logging: true,
// will be overwritten by modules
schema: createSchema({
typeDefs: `
type Query {
Expand Down
11 changes: 4 additions & 7 deletions packages/all-in/src/lib/index.ts
@@ -1,24 +1,21 @@
// Svelte Component
// export { default as KitQLInfo } from './KitQLInfo.svelte'
export { default as KitQLInfo } from './KitQLInfo.svelte'

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

// SvelteKit hooks
export type { KitQLHandleGraphQL } from './hooks/graphql.js'
export { handleGraphql } from './hooks/graphql.js'
export type { KitQLHandleGraphiQL } from './hooks/graphiql.js'
export { handleGraphiql } from './hooks/graphiql.js'
export { type KitQLHandleGraphQL, handleGraphql } from './hooks/graphql.js'
export { type KitQLHandleGraphiQL, handleGraphiql } from './hooks/graphiql.js'

// Prisma
// export { getKitQLPrisma } from './prisma/kitQLPrisma'

// GraphQL Config
export type { CodegenConfig as KitQLCodegenConfig } from '@graphql-codegen/cli'
export type { IGraphQLProject as KitQLProject } from 'graphql-config'
export type { KitQLProjects, KitQLConfig, KitQLScalar } from './graphql/graphqlConfig.js'
export { kitQLConfig } from './graphql/graphqlConfig.js'
export { type KitQLProjects, type KitQLConfig, type KitQLScalar, kitQLConfig } from './graphql/graphqlConfig.js'

// vite plugin
export { kitql } from './vite/plugin.js'
1 change: 1 addition & 0 deletions packages/all-in/src/lib/modules/_init/index.ts
@@ -1,4 +1,5 @@
import { createModule } from 'graphql-modules'

import { resolvers } from './$kitql/resolvers'
import { typeDefs } from './$kitql/typedefs'

Expand Down
1 change: 1 addition & 0 deletions packages/all-in/src/lib/modules/user/index.ts
@@ -1,6 +1,7 @@
import { createModule } from 'graphql-modules'
import { dirname } from 'path'
import { fileURLToPath } from 'url'

import { resolvers } from './$kitql/resolvers'
import { typeDefs } from './$kitql/typedefs'

Expand Down
Expand Up @@ -3,7 +3,7 @@ import type { UserModule } from '../$kitql/moduleTypes'
export const resolvers: UserModule.Resolvers = {
Mutation: {
userCreate: async (root, args, ctx) => {
return { id: '7', username: args.fields.username }
return { id: '77', username: args.fields.username }
},
},
}
7 changes: 4 additions & 3 deletions packages/all-in/src/lib/modules/user/resolvers/_Query.ts
@@ -1,14 +1,15 @@
import { topLevelFields } from '$lib/graphql/helper'
import type { UserConnection } from '$lib/graphql/$kitql/graphqlTypes'
import { topLevelFields } from '$lib/graphql/helper'
import { _InitModule } from '$lib/modules/_init/$kitql/moduleTypes'

import { UserModule } from '../$kitql/moduleTypes'

export const resolvers: UserModule.Resolvers = {
Query: {
user: async (root, args, ctx) => {
return {
id: '1',
username: 'JYC',
id: ctx.user.id.toString(),
username: ctx.user.name,
}
},

Expand Down
7 changes: 4 additions & 3 deletions packages/all-in/src/lib/vite/actionContexts.ts
@@ -1,7 +1,8 @@
import { createFolderIfNotExists } from './fileFolder'
import { toPascalCase } from './formatString'
import { join } from 'path'
import { write } from './readWrite'

import { createFolderIfNotExists } from './fileFolder.js'
import { toPascalCase } from './formatString.js'
import { write } from './readWrite.js'

export function actionContext(ctxModules: { ctxName: string; moduleName: string }[], outputFolder: string) {
const dataCtxModules = []
Expand Down
7 changes: 4 additions & 3 deletions packages/all-in/src/lib/vite/actionEnum.ts
@@ -1,8 +1,9 @@
import { existsSync } from 'fs'
import { join } from 'path'
import { createFolderIfNotExists } from './fileFolder'
import { toPascalCase } from './formatString'
import { write } from './readWrite'

import { createFolderIfNotExists } from './fileFolder.js'
import { toPascalCase } from './formatString.js'
import { write } from './readWrite.js'

export function actionEnum(
enumsModuleFolder: string,
Expand Down
5 changes: 3 additions & 2 deletions packages/all-in/src/lib/vite/actionModules.ts
@@ -1,6 +1,7 @@
import { join, posix } from 'path'
import { createFolderIfNotExists } from './fileFolder'
import { write } from './readWrite'

import { createFolderIfNotExists } from './fileFolder.js'
import { write } from './readWrite.js'

export function actionModules(modules: { directory: string; name: string }[], outputFolder: string) {
const modulesImports: string[] = []
Expand Down
5 changes: 3 additions & 2 deletions packages/all-in/src/lib/vite/actionResolvers.ts
@@ -1,6 +1,7 @@
import { join, posix } from 'path'
import { createFolderIfNotExists, getFiles, getFileWODots, getFileWOTS } from './fileFolder'
import { write } from './readWrite'

import { createFolderIfNotExists, getFiles, getFileWODots, getFileWOTS } from './fileFolder.js'
import { write } from './readWrite.js'

export function actionResolvers(moduleFolder: string, moduleOutputFolder: string) {
const resolversFolder = 'resolvers'
Expand Down
5 changes: 3 additions & 2 deletions packages/all-in/src/lib/vite/actionTypeDefs.ts
@@ -1,6 +1,7 @@
import { join } from 'path'
import { createFolderIfNotExists, getFiles } from './fileFolder'
import { read, write } from './readWrite'

import { createFolderIfNotExists, getFiles } from './fileFolder.js'
import { read, write } from './readWrite.js'

export function actionTypeDefs(moduleFolder: string, moduleOutputFolder: string) {
const typedefsFolder = 'typedefs'
Expand Down
1 change: 1 addition & 0 deletions packages/all-in/src/lib/vite/fileFolder.ts
@@ -1,6 +1,7 @@
import { existsSync, mkdirSync, readdirSync } from 'fs'
import glob from 'glob'
import { extname, join } from 'path'

const rootPath = process.cwd()

export const getDirectories = (source: string) => {
Expand Down
@@ -1,14 +1,15 @@
import { Log, logGreen, logRed } from '@kitql/helper'
import { basename, extname } from 'path'
import { actionContext } from './actionContexts'
import { actionEnum } from './actionEnum'
import { actionModules } from './actionModules'
import { actionResolvers } from './actionResolvers'
import { actionTypeDefs } from './actionTypeDefs'
import { getDirectories, getFullPath } from './fileFolder'
import { type KitQLVite } from './KitQLVite'
import { getPrismaEnum } from './prismaHelper'
import { readLines } from './readWrite'

import { type KitQLVite } from './KitQLVite.js'
import { actionContext } from './actionContexts.js'
import { actionEnum } from './actionEnum.js'
import { actionModules } from './actionModules.js'
import { actionResolvers } from './actionResolvers.js'
import { actionTypeDefs } from './actionTypeDefs.js'
import { getDirectories, getFullPath } from './fileFolder.js'
import { getPrismaEnum } from './prismaHelper.js'
import { readLines } from './readWrite.js'

export function generate(config?: KitQLVite) {
const log = new Log('KitQL')
Expand Down
3 changes: 2 additions & 1 deletion packages/all-in/src/lib/vite/plugin.ts
@@ -1,6 +1,7 @@
import type { Plugin } from 'vite'
import { generate } from '.'

import type { KitQLVite } from './KitQLVite'
import { generate } from './generate.js'

export function kitql(config?: KitQLVite): Plugin {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/all-in/src/lib/vite/prismaHelper.ts
@@ -1,4 +1,4 @@
import { toPascalCase } from './formatString'
import { toPascalCase } from './formatString.js'

export function getPrismaEnum(lines: string[]): Record<string, string[]> {
const enums = {}
Expand Down
1 change: 1 addition & 0 deletions packages/all-in/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"moduleResolution": "NodeNext",
"importsNotUsedAsValues": "preserve",
"paths": {
"$lib": ["src/lib"],
Expand Down
2 changes: 2 additions & 0 deletions packages/all-in/vite.config.ts
@@ -1,6 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite'
import { type UserConfig } from 'vite'

import { kitql } from './src/lib/vite/plugin'

// import { kitql } from '@kitql/all-in'

const config: UserConfig = {
Expand Down
1 change: 1 addition & 0 deletions packages/helper/test/Log.spec.ts
@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { Log, logCyan, logGreen, logMagneta, logRed, logYellow } from '../src/Log'
import { stry } from '../src/stry'

Expand Down
1 change: 1 addition & 0 deletions packages/helper/test/queryStringApprend.spec.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest'

import { queryStringApprend } from '../src/queryStringApprend'

describe('kitql - helper - queryStringApprend', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/helper/test/sleep.spec.ts
@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { sleep } from '../src/sleep'

describe('kitql - helper - sleep', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/helper/test/stry.spec.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest'

import { stry } from '../src/stry'

describe('kitql - helper - stry', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/module-codegen/src/actionContexts.ts
@@ -1,6 +1,7 @@
import { join } from 'path'

import { createFolderIfNotExists } from './fileFolder'
import { toPascalCase } from './formatString'
import { join } from 'path'
import { write } from './readWrite'

export function actionContext(ctxModules: { ctxName: string; moduleName: string }[], outputFolder: string) {
Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/actionEnum.ts
@@ -1,5 +1,6 @@
import { existsSync } from 'fs'
import { join } from 'path'

import { createFolderIfNotExists } from './fileFolder'
import { toPascalCase } from './formatString'
import { write } from './readWrite'
Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/actionModuleContext.ts
@@ -1,4 +1,5 @@
import { join, basename, extname } from 'path'

import { createFolderIfNotExists } from './fileFolder'
import { toPascalCase } from './formatString'
import { write } from './readWrite'
Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/actionModules.ts
@@ -1,4 +1,5 @@
import { join, posix } from 'path'

import { createFolderIfNotExists } from './fileFolder'
import { write } from './readWrite'

Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/actionResolvers.ts
@@ -1,4 +1,5 @@
import { join, posix } from 'path'

import { createFolderIfNotExists, getFiles, getFileWODots, getFileWOTS } from './fileFolder'
import { write } from './readWrite'

Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/actionTypeDefs.ts
@@ -1,4 +1,5 @@
import { join } from 'path'

import { createFolderIfNotExists, getFiles } from './fileFolder'
import { read, write } from './readWrite'

Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/defaultConfigFile.ts
@@ -1,4 +1,5 @@
import path from 'path'

import { write } from './readWrite'

type TEnumsModuleConfig = {
Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/fileFolder.ts
@@ -1,6 +1,7 @@
import { existsSync, mkdirSync, readdirSync } from 'fs'
import glob from 'glob'
import { extname, join } from 'path'

const rootPath = process.cwd()

export const getDirectories = (source: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/module-codegen/src/index.ts
Expand Up @@ -2,6 +2,7 @@ import { Log, logCyan, logGreen, logRed } from '@kitql/helper'
import fs from 'fs'
import { join, basename, extname } from 'path'
import YAML from 'yaml'

import { actionContext } from './actionContexts'
import { actionEnum } from './actionEnum'
import { actionModuleContext } from './actionModuleContext'
Expand Down

1 comment on commit f2596b1

@vercel
Copy link

@vercel vercel bot commented on f2596b1 Oct 19, 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-jycouet.vercel.app
kitql-git-main-jycouet.vercel.app
kitql.dev
kitql.vercel.app
www.kitql.dev

Please sign in to comment.