diff --git a/packages/e2e/__tests__/databases/mongo.ts b/packages/e2e/__tests__/databases/mongo.ts index a36857993..2ee5ee99a 100644 --- a/packages/e2e/__tests__/databases/mongo.ts +++ b/packages/e2e/__tests__/databases/mongo.ts @@ -15,7 +15,7 @@ export class DatabaseTest implements DatabaseTestInterface { public async start() { (mongoose as any).Promise = global.Promise; - await mongoose.connect(connectionString); + await mongoose.connect(connectionString, { useNewUrlParser: true }); await mongoose.connection.dropDatabase(); } diff --git a/packages/e2e/package.json b/packages/e2e/package.json index e2d1e59e2..74a7e7779 100644 --- a/packages/e2e/package.json +++ b/packages/e2e/package.json @@ -44,9 +44,6 @@ "@accounts/typeorm": "^0.19.0", "@accounts/types": "^0.19.0", "@graphql-modules/core": "0.7.11", - "@types/lodash": "4.14.138", - "@types/mongoose": "5.5.17", - "@types/node-fetch": "2.5.0", "apollo-boost": "0.4.4", "apollo-server": "2.9.3", "body-parser": "1.19.0", diff --git a/packages/graphql-api/package.json b/packages/graphql-api/package.json index 4a98d54b2..ecf9177a5 100644 --- a/packages/graphql-api/package.json +++ b/packages/graphql-api/package.json @@ -34,6 +34,7 @@ "@gql2ts/from-schema": "1.10.1", "@gql2ts/types": "1.9.0", "@graphql-modules/core": "0.7.11", + "@types/graphql-type-json": "0.3.2", "@types/jest": "24.0.18", "@types/request-ip": "0.0.34", "concurrently": "4.1.2", @@ -59,6 +60,7 @@ }, "dependencies": { "graphql-toolkit": "^0.5.12", + "graphql-type-json": "0.3.0", "request-ip": "2.1.3", "tslib": "1.10.0" } diff --git a/packages/graphql-api/src/models.ts b/packages/graphql-api/src/models.ts index 33934612c..09f93ae46 100644 --- a/packages/graphql-api/src/models.ts +++ b/packages/graphql-api/src/models.ts @@ -27,20 +27,6 @@ export interface TwoFactorSecretKeyInput { otpauth_url?: Maybe; } -export interface AuthenticateParamsInput { - access_token?: Maybe; - - access_token_secret?: Maybe; - - provider?: Maybe; - - password?: Maybe; - - user?: Maybe; - - code?: Maybe; -} - export interface UserInput { id?: Maybe; @@ -49,6 +35,12 @@ export interface UserInput { username?: Maybe; } +export type Json = any; + +// ==================================================== +// Scalars +// ==================================================== + // ==================================================== // Types // ==================================================== @@ -184,10 +176,10 @@ export interface RefreshTokensMutationArgs { export interface AuthenticateMutationArgs { serviceName: string; - params: AuthenticateParamsInput; + params: Json; } -import { GraphQLResolveInfo } from 'graphql'; +import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'; export type Resolver = ( parent: Parent, @@ -498,7 +490,7 @@ export type MutationAuthenticateResolver< export interface MutationAuthenticateArgs { serviceName: string; - params: AuthenticateParamsInput; + params: Json; } export interface LoginResultResolvers { @@ -592,6 +584,10 @@ export interface DeprecatedDirectiveArgs { reason?: string; } +export interface JSONScalarConfig extends GraphQLScalarTypeConfig { + name: 'JSON'; +} + export type IResolvers = { Query?: QueryResolvers; TwoFactorSecretKey?: TwoFactorSecretKeyResolvers; @@ -601,6 +597,7 @@ export type IResolvers = { LoginResult?: LoginResultResolvers; Tokens?: TokensResolvers; ImpersonateReturn?: ImpersonateReturnResolvers; + Json?: GraphQLScalarType; } & { [typeName: string]: never }; export type IDirectiveResolvers = { diff --git a/packages/graphql-api/src/modules/accounts/index.ts b/packages/graphql-api/src/modules/accounts/index.ts index 9c95f1306..71deb36f8 100644 --- a/packages/graphql-api/src/modules/accounts/index.ts +++ b/packages/graphql-api/src/modules/accounts/index.ts @@ -15,6 +15,7 @@ import { AuthenticatedDirective } from '../../utils/authenticated-directive'; import { context } from '../../utils'; import AccountsPassword from '@accounts/password'; import { mergeTypeDefs } from 'graphql-toolkit'; +import GraphQLJSON from 'graphql-type-json'; export interface AccountsRequest { req: IncomingMessage; @@ -61,6 +62,8 @@ export const AccountsModule: GraphQLModule< ), resolvers: ({ config }) => ({ + // Inject JSON custom scalar + JSON: GraphQLJSON, [config.rootQueryName || 'Query']: Query, [config.rootMutationName || 'Mutation']: Mutation, User: UserResolvers, diff --git a/packages/graphql-api/src/modules/accounts/schema/mutation.ts b/packages/graphql-api/src/modules/accounts/schema/mutation.ts index 647a3c85a..31ea7b89a 100644 --- a/packages/graphql-api/src/modules/accounts/schema/mutation.ts +++ b/packages/graphql-api/src/modules/accounts/schema/mutation.ts @@ -9,6 +9,6 @@ export default (config: AccountsModuleConfig) => gql` # Example: Login with password # authenticate(serviceName: "password", params: {password: "", user: {email: ""}}) - authenticate(serviceName: String!, params: AuthenticateParamsInput!): LoginResult + authenticate(serviceName: String!, params: JSON!): LoginResult } `; diff --git a/packages/graphql-api/src/modules/accounts/schema/types.ts b/packages/graphql-api/src/modules/accounts/schema/types.ts index 74354c5fa..3fcb67c0b 100644 --- a/packages/graphql-api/src/modules/accounts/schema/types.ts +++ b/packages/graphql-api/src/modules/accounts/schema/types.ts @@ -3,6 +3,7 @@ import { AccountsModuleConfig } from '..'; export default ({ userAsInterface }: AccountsModuleConfig) => gql` directive @auth on FIELD_DEFINITION | OBJECT + scalar JSON type Tokens { refreshToken: String @@ -36,19 +37,4 @@ export default ({ userAsInterface }: AccountsModuleConfig) => gql` email: String username: String } - - input AuthenticateParamsInput { - # Twitter, Instagram - access_token: String - # Twitter - access_token_secret: String - # OAuth - provider: String - # Password - password: String - # Password - user: UserInput - # Two factor - code: String - } `; diff --git a/packages/graphql-client/src/graphql/login-with-service.mutation.ts b/packages/graphql-client/src/graphql/login-with-service.mutation.ts index ee7227a50..eb9642df3 100644 --- a/packages/graphql-client/src/graphql/login-with-service.mutation.ts +++ b/packages/graphql-client/src/graphql/login-with-service.mutation.ts @@ -1,7 +1,7 @@ import gql from 'graphql-tag'; export const loginWithServiceMutation = gql` - mutation($serviceName: String!, $params: AuthenticateParamsInput!) { + mutation($serviceName: String!, $params: JSON!) { authenticate(serviceName: $serviceName, params: $params) { sessionId tokens { diff --git a/yarn.lock b/yarn.lock index 140f5bd68..498d6272c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1364,9 +1364,9 @@ integrity sha512-dBtBbrc+qTHy1WdfHYjBwRln4+LWqASWakLHsWHR2NWHIFkv4W3O070IGoGLEBrJBvct3r0L1BUPuvURi7kYUQ== "@types/babel__core@^7.1.0": - version "7.1.2" - resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.2.tgz#608c74f55928033fce18b99b213c16be4b3d114f" - integrity sha512-cfCCrFmiGY/yq0NuKNxIQvZFy9kY/1immpSpTngOnyIbD4+eJOG5mxphhHDv3CHL9GltO4GcKr54kGBg3RNdbg== + version "7.1.3" + resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.3.tgz#e441ea7df63cd080dfcd02ab199e6d16a735fc30" + integrity sha512-8fBo0UR2CcwWxeX7WIIgJ7lXjasFxoYgRnFHUj+hRvKkpiBJbxhdAPTCY6/ZKM0uxANFVzt4yObSLuTiTnazDA== dependencies: "@babel/parser" "^7.1.0" "@babel/types" "^7.0.0" @@ -1508,6 +1508,13 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/graphql-type-json@0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@types/graphql-type-json/-/graphql-type-json-0.3.2.tgz#1a7105e6546fc1630a5db4834bfbc0eb554986e4" + integrity sha512-c1cq4o8EhY0Z39ua8UXwG8uBs23xBYA/Uw0tXFl6SuTUpkVv/IJqf6pHQbfdC7nwFRhX2ifTOV/UIg0Q/IJsbg== + dependencies: + graphql "^14.5.3" + "@types/graphql-upload@^8.0.0": version "8.0.3" resolved "https://registry.yarnpkg.com/@types/graphql-upload/-/graphql-upload-8.0.3.tgz#b371edb5f305a2a1f7b7843a890a2a7adc55c3ec" @@ -6615,6 +6622,11 @@ graphql-tools@4.0.4, graphql-tools@4.0.5, graphql-tools@^4.0.0, graphql-tools@^4 iterall "^1.1.3" uuid "^3.1.0" +graphql-type-json@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.0.tgz#bb32e1b74bf52ebc690f9df12b4067bc061f818a" + integrity sha512-lnxg5HiB95yxy+/5cDKtP6pZo0zgntsOmqsjeCBXFGJ4YoMF3+1YaSEKWJntNTu+VsAm3zf6lPxFpp1kxzofLA== + graphql-upload@^8.0.2: version "8.0.7" resolved "https://registry.yarnpkg.com/graphql-upload/-/graphql-upload-8.0.7.tgz#8644264e241529552ea4b3797e7ee15809cf01a3"