Skip to content

Commit

Permalink
⛑️🐉 ↝ Adding YAML configuration for GraphQL interaction with #16
Browse files Browse the repository at this point in the history
I've moved the main authentication function (Flask, Moralis) in the `server` directory into the `api/auth` dir. No longer appears to work (apparently an issue with `magic-sdk` not being included in another node package. We'll fix this later, but since we're getting Lens to handle the signature process for the next part of this webapp, that isn't going to be fixed for now.

Signal-K/Silfur#24
  • Loading branch information
Gizmotronn committed Jan 1, 2023
1 parent 2ec4eb7 commit 95feace
Show file tree
Hide file tree
Showing 18 changed files with 7,551 additions and 145 deletions.
19 changes: 19 additions & 0 deletions Server/frontend/codegen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 1. Schema -> Path of graphql schema
schema: 'https://api.lens.dev'

# 2. Documents -> Path of the graphql operations
documents: './graphql/*.graphql'

# 3. Output -> Where should the output be generated
generates:
graphql/generated.ts:
plugins:
- typescript
- typescript-operations
- typescript-react-query
- fragment-matcher
config:
dedupeFragments: true
fetcher:
func: './auth-fetcher#fetcher'
isReactHook: false
33 changes: 33 additions & 0 deletions Server/frontend/graphql/auth-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TableDataCellComponent } from "react-markdown/lib/ast-to-react";

const endpoint = 'https://api.lens.dev';

export const fetcher = <TData, TVariables>(
query: string,
variables?: TVariables,
options?: RequestInit['headers']
): (() => Promise<TData>) => {
return async () => {
const res = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options,
// Add Lens auth token here
},
body: JSON.stringify({
query,
variables
})
})

const json = await res.json()

if (json.errors) {
const { message } = json.errors[0] || {}
throw new Error(message || 'Error…')
}

return json.data
}
}
Loading

0 comments on commit 95feace

Please sign in to comment.