parent
de7624072d
commit
015561b6f8
|
@ -0,0 +1 @@
|
|||
node_modules
|
|
@ -0,0 +1,11 @@
|
|||
schema: http://localhost:4000/graphql
|
||||
documents: './queries.ts'
|
||||
generates:
|
||||
./generates.ts:
|
||||
plugins:
|
||||
- typescript
|
||||
- typescript-operations
|
||||
- typescript-react-query
|
||||
config:
|
||||
fetcher:
|
||||
func: './fetcher#fetcher'
|
|
@ -0,0 +1,25 @@
|
|||
import {config, fetch_config} from "../config";
|
||||
|
||||
export function fetcher<TData, TVariables>(query: string, variables?: TVariables) {
|
||||
return async (): Promise<TData> => {
|
||||
await fetch_config()
|
||||
const res = await fetch(`${config.backend_base_url}/graphql`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ query, variables }),
|
||||
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
if (json.errors) {
|
||||
const { message } = json.errors[0];
|
||||
console.error('Graphql Error:', message, query, variables)
|
||||
}
|
||||
|
||||
return json.data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
import { useQuery, UseQueryOptions } from 'react-query';
|
||||
import { fetcher } from './fetcher';
|
||||
export type Maybe<T> = T | null;
|
||||
export type InputMaybe<T> = Maybe<T>;
|
||||
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
|
||||
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
|
||||
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
|
||||
/** All built-in and custom scalars, mapped to their actual values */
|
||||
export type Scalars = {
|
||||
ID: string;
|
||||
String: string;
|
||||
Boolean: boolean;
|
||||
Int: number;
|
||||
Float: number;
|
||||
/** The 'Long' scalar type represents non-fractional signed whole numeric values. Long can represent values between -(2^64) and 2^64 - 1. */
|
||||
Long: any;
|
||||
};
|
||||
|
||||
/** Authentication requires either a valid mail+password combination or a jwt obtained by an earlier login. */
|
||||
export type Auth = {
|
||||
/** Self descriptive. */
|
||||
jwt: Scalars['String'];
|
||||
/** Self descriptive. */
|
||||
mail: Scalars['String'];
|
||||
/** Self descriptive. */
|
||||
password: Scalars['String'];
|
||||
};
|
||||
|
||||
/** The type that query operations will be rooted at. */
|
||||
export type QueryType = {
|
||||
__typename?: 'QueryType';
|
||||
/** Export an encrypted database dump */
|
||||
export?: Maybe<Export>;
|
||||
/** The offers that are visible for the ngo, belonging to the login */
|
||||
get_offers?: Maybe<Array<Get_Offers>>;
|
||||
/** For a username+password get a jwt containing the login:id */
|
||||
login: Login;
|
||||
};
|
||||
|
||||
|
||||
/** The type that query operations will be rooted at. */
|
||||
export type QueryTypeExportArgs = {
|
||||
password: Scalars['String'];
|
||||
};
|
||||
|
||||
|
||||
/** The type that query operations will be rooted at. */
|
||||
export type QueryTypeGet_OffersArgs = {
|
||||
auth: Auth;
|
||||
};
|
||||
|
||||
|
||||
/** The type that query operations will be rooted at. */
|
||||
export type QueryTypeLoginArgs = {
|
||||
auth: Auth;
|
||||
};
|
||||
|
||||
/** Export an encrypted database dump */
|
||||
export type Export = {
|
||||
__typename?: 'export';
|
||||
err?: Maybe<Scalars['String']>;
|
||||
/** Self descriptive. */
|
||||
exit: Scalars['Int'];
|
||||
out?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
/** The offers that are visible for the ngo, belonging to the login */
|
||||
export type Get_Offers = {
|
||||
__typename?: 'get_offers';
|
||||
accessible?: Maybe<Scalars['Boolean']>;
|
||||
note?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
/** For a username+password get a jwt containing the login:id */
|
||||
export type Login = {
|
||||
__typename?: 'login';
|
||||
jwt?: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
export type LoginQueryVariables = Exact<{
|
||||
auth: Auth;
|
||||
}>;
|
||||
|
||||
|
||||
export type LoginQuery = { __typename?: 'QueryType', login: { __typename?: 'login', jwt?: string | null } };
|
||||
|
||||
export type GetOffersQueryVariables = Exact<{
|
||||
auth: Auth;
|
||||
}>;
|
||||
|
||||
|
||||
export type GetOffersQuery = { __typename?: 'QueryType', get_offers?: Array<{ __typename?: 'get_offers', accessible?: boolean | null, note?: string | null }> | null };
|
||||
|
||||
|
||||
export const LoginDocument = `
|
||||
query Login($auth: Auth!) {
|
||||
login(auth: $auth) {
|
||||
jwt
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const useLoginQuery = <
|
||||
TData = LoginQuery,
|
||||
TError = unknown
|
||||
>(
|
||||
variables: LoginQueryVariables,
|
||||
options?: UseQueryOptions<LoginQuery, TError, TData>
|
||||
) =>
|
||||
useQuery<LoginQuery, TError, TData>(
|
||||
['Login', variables],
|
||||
fetcher<LoginQuery, LoginQueryVariables>(LoginDocument, variables),
|
||||
options
|
||||
);
|
||||
export const GetOffersDocument = `
|
||||
query GetOffers($auth: Auth!) {
|
||||
get_offers(auth: $auth) {
|
||||
accessible
|
||||
note
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const useGetOffersQuery = <
|
||||
TData = GetOffersQuery,
|
||||
TError = unknown
|
||||
>(
|
||||
variables: GetOffersQueryVariables,
|
||||
options?: UseQueryOptions<GetOffersQuery, TError, TData>
|
||||
) =>
|
||||
useQuery<GetOffersQuery, TError, TData>(
|
||||
['GetOffers', variables],
|
||||
fetcher<GetOffersQuery, GetOffersQueryVariables>(GetOffersDocument, variables),
|
||||
options
|
||||
);
|
|
@ -0,0 +1,14 @@
|
|||
import { gql } from 'graphql-request'
|
||||
|
||||
export const login = gql`
|
||||
query Login($auth: Auth!) {
|
||||
login(auth: $auth) {jwt}
|
||||
}`
|
||||
|
||||
export const get_offers = gql`
|
||||
query GetOffers($auth: Auth!) {
|
||||
get_offers(auth: $auth) {
|
||||
accessible
|
||||
note
|
||||
}
|
||||
}`
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "beherbergung-search-frontend",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"generate": "cd codegen && graphql-codegen generate",
|
||||
"dev": "next dev",
|
||||
"build": "next build --no-lint",
|
||||
"start": "next start",
|
||||
"export": "next export"
|
||||
},
|
||||
"dependencies": {
|
||||
"graphql-request": "^3.7.0",
|
||||
"react-query": "^3.34.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/cli": "^2.3.0",
|
||||
"@graphql-codegen/typescript": "^2.4.1",
|
||||
"@graphql-codegen/typescript-operations": "^2.2.1",
|
||||
"@graphql-codegen/typescript-react-query": "^3.2.2",
|
||||
"typescript": "4.5.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue