mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-08 21:15:05 -05:00
updated backend for brightId (#362)
* updated backend for brightId * updated schema * removed unwanted console logs * made brightId context constant
This commit is contained in:
@@ -7,6 +7,7 @@ interface IConfig {
|
||||
imgixToken: string;
|
||||
infuraId: string;
|
||||
pSEEDAddress: string;
|
||||
brightIdNodeUrl: string;
|
||||
}
|
||||
|
||||
function parseEnv<T extends string | number>(
|
||||
@@ -45,4 +46,8 @@ export const CONFIG: IConfig = {
|
||||
process.env.NEXT_PUBLIC_INFURA_ID,
|
||||
'781d8466252d47508e177b8637b1c2fd',
|
||||
),
|
||||
brightIdNodeUrl: parseEnv(
|
||||
process.env.BRIGHTID_NODE_URL,
|
||||
'https://app.brightid.org',
|
||||
),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { CONFIG } from '../../../../config';
|
||||
import { QueryResolvers } from '../../autogen/types';
|
||||
|
||||
const CONTEXT = 'MetaGame';
|
||||
|
||||
const ENDPOINT = `${CONFIG.brightIdNodeUrl}/node/v5/verifications/${CONTEXT}`;
|
||||
|
||||
export const getBrightIdStatus: QueryResolvers['getBrightIdStatus'] = async (
|
||||
_,
|
||||
{ contextId },
|
||||
) => {
|
||||
if (!contextId) return null;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${ENDPOINT}/${contextId}`);
|
||||
if (!response.ok) return null;
|
||||
const responseData = await response.json();
|
||||
return responseData.data;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -1,14 +1,18 @@
|
||||
import { makeExecutableSchema } from 'graphql-tools';
|
||||
|
||||
import { getBrightIdStatus } from './resolvers/brightId/resolver';
|
||||
import { getDaoHausMemberships } from './resolvers/daohaus/resolver';
|
||||
import { getBoxProfile } from './resolvers/getBoxProfile/resolver';
|
||||
import { typeDefs } from './typeDefs';
|
||||
import { uuid } from './types/uuid';
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
getBoxProfile,
|
||||
getDaoHausMemberships,
|
||||
getBrightIdStatus,
|
||||
},
|
||||
uuid,
|
||||
};
|
||||
|
||||
export const schema = makeExecutableSchema({ typeDefs, resolvers });
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import { gql } from 'graphql-request/dist';
|
||||
|
||||
export const typeDefs = gql`
|
||||
scalar uuid
|
||||
|
||||
type Query {
|
||||
getBoxProfile(address: String): BoxProfile
|
||||
getDaoHausMemberships(memberAddress: String): [Member!]!
|
||||
getBrightIdStatus(contextId: uuid): BrightIdStatus
|
||||
}
|
||||
|
||||
type BrightIdStatus {
|
||||
unique: Boolean!
|
||||
app: String!
|
||||
context: String!
|
||||
contextIds: [String!]!
|
||||
}
|
||||
|
||||
type BoxProfile {
|
||||
|
||||
38
packages/backend/src/handlers/remote-schemas/types/uuid.ts
Normal file
38
packages/backend/src/handlers/remote-schemas/types/uuid.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { GraphQLScalarType } from 'graphql';
|
||||
import { Kind } from 'graphql/language';
|
||||
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
const nilUUID = '00000000-0000-0000-0000-000000000000';
|
||||
|
||||
const isUUID = (value: string) => {
|
||||
return uuidRegex.test(value) || nilUUID === value;
|
||||
};
|
||||
|
||||
export const uuid = new GraphQLScalarType({
|
||||
name: 'uuid',
|
||||
description:
|
||||
'The `uuid` scalar type represents UUID values as specified by [RFC 4122](https://tools.ietf.org/html/rfc4122).',
|
||||
serialize: (value) => {
|
||||
if (!isUUID(value)) {
|
||||
throw new TypeError(`UUID cannot represent non-UUID value: ${value}`);
|
||||
}
|
||||
|
||||
return value.toLowerCase();
|
||||
},
|
||||
parseValue: (value) => {
|
||||
if (!isUUID(value)) {
|
||||
throw new TypeError(`UUID cannot represent non-UUID value: ${value}`);
|
||||
}
|
||||
|
||||
return value.toLowerCase();
|
||||
},
|
||||
parseLiteral: (ast) => {
|
||||
if (ast.kind === Kind.STRING) {
|
||||
if (isUUID(ast.value)) {
|
||||
return ast.value;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user