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

Revert "➖ Old Dependencies – Removing @tinacms/graphql-old and /datalayer-old" #2255

Merged
merged 3 commits into from
Sep 27, 2024
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"@react-three/fiber": "^8.16.8",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tinacms/auth": "1.0.6",
"@tinacms/datalayer-old": "npm:@tinacms/datalayer@0.2.3",
"@tinacms/graphql-old": "npm:@tinacms/graphql@0.60.0",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"@vercel/postgres": "^0.5.1",
Expand Down
88 changes: 88 additions & 0 deletions pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as datalayerPackage from '@tinacms/datalayer-old'
import * as gqlPackage from '@tinacms/graphql-old'

export default async function feedback(req, res) {
class InMemoryStore extends datalayerPackage.LevelStore {
public supportsSeeding() {
return true
}
public supportsIndexing() {
return false
}
}
class InMemoryBridge {
public rootPath: string
private mockFileSystem: { [filepath: string]: string } | undefined
private content: string
constructor(rootPath: string, content: string) {
this.rootPath = rootPath
this.mockFileSystem = mockFileSystem(content)
this.content = content
}
public glob = async (pattern: string) => {
return Object.keys(this.mockFileSystem).filter((key) =>
key.startsWith(pattern)
)
}

public delete = async (filepath: string) => {
const mockData = await this.getMockData()
delete mockData[filepath]
}

public get = async (filepath: string) => {
const mockData = await this.getMockData()
const value = mockData[filepath]
if (!value) {
throw new Error(`Unable to find record for ${filepath}`)
}
return value
}
public put = async (filepath: string, data: string) => {
const mockData = await this.getMockData()
this.mockFileSystem = { ...mockData, [filepath]: data }
}

public getMockData = async () => {
return this.mockFileSystem
}
public async putConfig(filepath: string, data: string) {
await this.put(filepath, data)
}
public supportsBuilding() {
return true
}
}

const mockFileSystem = (content: string) => ({
'posts/hello-world.md': content,
'authors/pedro.md': `---\nname: Pedro\navatar: https://images.unsplash.com/photo-1555959910-80920d0698a4?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=1301&q=80\n---`,
'authors/napolean.md': `---\nname: Napolean\navatar: https://images.unsplash.com/photo-1606721977440-13e6c3a3505a?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=344&q=80\n---`,
})
// @ts-ignore
const schema = JSON.parse(req.query.schema)
const database = await gqlPackage.createDatabase({
// @ts-ignore
bridge: new InMemoryBridge('', req.query.content),
// @ts-ignore
store: new InMemoryStore('', true),
})

const query = req.query.query
const variables = req.query.variables
? // as string since this can be an array of strings (we're not using it that way)
JSON.parse(req.query.variables as string)
: {}
try {
await gqlPackage?.indexDB({ database, config: schema, buildSDK: false })
const result = await gqlPackage.resolve({
database,
query,
variables,
})
return res.json(result)
} catch (e) {
res.status(500)
return res.json({ errors: [{ message: e.message }] })
}
}
Loading
Loading