diff --git a/package.json b/package.json index 8c92be44..d2ae55da 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@graphql-codegen/typescript-operations": "^2.5.6", "@graphql-codegen/typescript-resolvers": "^2.7.6", "@graphql-eslint/eslint-plugin": "^3.12.0", - "@ndla/types-backend": "^0.2.23", + "@ndla/types-backend": "^0.2.26", "@ndla/types-embed": "^4.0.0", "@ndla/types-taxonomy": "^1.0.19", "@types/bunyan": "^1.8.5", diff --git a/src/api/learningpathApi.ts b/src/api/learningpathApi.ts index 2e4638be..56eb208b 100644 --- a/src/api/learningpathApi.ts +++ b/src/api/learningpathApi.ts @@ -78,13 +78,19 @@ export async function fetchLearningpath( }; } -export const fetchExamLockStatus = async ( +export const fetchConfig = async ( + configKey: string, context: Context, ): Promise => { const response = await fetch( - '/learningpath-api/v1/config/MY_NDLA_WRITE_RESTRICTED', + `/learningpath-api/v1/config/${configKey}`, context, ); - const examLockStatus: IConfigMetaRestricted = await resolveJson(response); - return examLockStatus; + const config: IConfigMetaRestricted = await resolveJson(response); + return config; }; + +export const fetchExamLockStatus = async ( + context: Context, +): Promise => + fetchConfig('MY_NDLA_WRITE_RESTRICTED', context); diff --git a/src/resolvers/learningpathResolvers.ts b/src/resolvers/learningpathResolvers.ts index 8d11369d..1894e819 100644 --- a/src/resolvers/learningpathResolvers.ts +++ b/src/resolvers/learningpathResolvers.ts @@ -6,10 +6,11 @@ * */ -import { IConfigMetaRestricted } from '@ndla/types-backend/learningpath-api'; import { fetchLearningpath, fetchNode, fetchOembed } from '../api'; -import { fetchExamLockStatus } from '../api/learningpathApi'; +import { fetchConfig, fetchExamLockStatus } from '../api/learningpathApi'; import { + GQLConfigMetaBoolean, + GQLConfigMetaStringList, GQLLearningpath, GQLLearningpathStep, GQLLearningpathStepOembed, @@ -31,8 +32,23 @@ export const Query = { _: any, __: any, context: ContextWithLoaders, - ): Promise { - return fetchExamLockStatus(context); + ): Promise { + const config = await fetchExamLockStatus(context); + if (typeof config.value !== 'boolean') { + throw new Error('Invalid exam lock status'); + } + + return { key: config.key, value: config.value }; + }, + async arenaEnabledOrgs( + _: any, + __: any, + context: ContextWithLoaders, + ): Promise { + const config = await fetchConfig('ARENA_ENABLED_ORGS', context); + if (typeof config.value === 'boolean') + throw new Error('Invalid arena enabled orgs'); + return { key: config.key, value: config.value }; }, }; diff --git a/src/schema.ts b/src/schema.ts index e8824b9d..b4380d69 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1126,11 +1126,18 @@ export const typeDefs = gql` id: Int! favoriteSubjects: [String!]! role: String! + arenaEnabled: Boolean! + organization: String! } - type ConfigMetaRestricted { + type ConfigMetaBoolean { key: String! - value: String! + value: Boolean! + } + + type ConfigMetaStringList { + key: String! + value: [String!]! } type ResourceMetaData { @@ -1323,7 +1330,8 @@ export const typeDefs = gql` allFolderResources(size: Int): [FolderResource!]! personalData: MyNdlaPersonalData! image(id: String!): ImageMetaInformationV2 - examLockStatus: ConfigMetaRestricted! + examLockStatus: ConfigMetaBoolean! + arenaEnabledOrgs: ConfigMetaStringList resourceEmbed(id: String!, type: String!): ResourceEmbed! resourceEmbeds(resources: [ResourceEmbedInput!]!): ResourceEmbed! arenaCategories: [ArenaCategory!]! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 2ef0e598..988b6335 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -369,10 +369,16 @@ export type GQLConceptResult = { totalCount: Scalars['Int']; }; -export type GQLConfigMetaRestricted = { - __typename?: 'ConfigMetaRestricted'; +export type GQLConfigMetaBoolean = { + __typename?: 'ConfigMetaBoolean'; key: Scalars['String']; - value: Scalars['String']; + value: Scalars['Boolean']; +}; + +export type GQLConfigMetaStringList = { + __typename?: 'ConfigMetaStringList'; + key: Scalars['String']; + value: Array; }; export type GQLContributor = { @@ -949,8 +955,10 @@ export type GQLMutationUpdatePersonalDataArgs = { export type GQLMyNdlaPersonalData = { __typename?: 'MyNdlaPersonalData'; + arenaEnabled: Scalars['Boolean']; favoriteSubjects: Array; id: Scalars['Int']; + organization: Scalars['String']; role: Scalars['String']; }; @@ -1063,6 +1071,7 @@ export type GQLQuery = { allFolderResources: Array; arenaCategories: Array; arenaCategory?: Maybe; + arenaEnabledOrgs?: Maybe; arenaRecentTopics: Array; arenaTopic?: Maybe; arenaTopicsByUser: Array; @@ -1076,7 +1085,7 @@ export type GQLQuery = { conceptSearch?: Maybe; coreElement?: Maybe; coreElements?: Maybe>; - examLockStatus: GQLConfigMetaRestricted; + examLockStatus: GQLConfigMetaBoolean; filmfrontpage?: Maybe; folder: GQLFolder; folderResourceMeta?: Maybe; @@ -1880,7 +1889,8 @@ export type GQLResolversTypes = { ConceptFolderResourceMeta: ResolverTypeWrapper; ConceptLicense: ResolverTypeWrapper; ConceptResult: ResolverTypeWrapper; - ConfigMetaRestricted: ResolverTypeWrapper; + ConfigMetaBoolean: ResolverTypeWrapper; + ConfigMetaStringList: ResolverTypeWrapper; Contributor: ResolverTypeWrapper; Copyright: ResolverTypeWrapper; CoreElement: ResolverTypeWrapper; @@ -2027,7 +2037,8 @@ export type GQLResolversParentTypes = { ConceptFolderResourceMeta: GQLConceptFolderResourceMeta; ConceptLicense: GQLConceptLicense; ConceptResult: GQLConceptResult; - ConfigMetaRestricted: GQLConfigMetaRestricted; + ConfigMetaBoolean: GQLConfigMetaBoolean; + ConfigMetaStringList: GQLConfigMetaStringList; Contributor: GQLContributor; Copyright: GQLCopyright; CoreElement: GQLCoreElement; @@ -2489,9 +2500,15 @@ export type GQLConceptResultResolvers; }; -export type GQLConfigMetaRestrictedResolvers = { +export type GQLConfigMetaBooleanResolvers = { key?: Resolver; - value?: Resolver; + value?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + +export type GQLConfigMetaStringListResolvers = { + key?: Resolver; + value?: Resolver, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }; @@ -2981,8 +2998,10 @@ export type GQLMutationResolvers = { + arenaEnabled?: Resolver; favoriteSubjects?: Resolver, ParentType, ContextType>; id?: Resolver; + organization?: Resolver; role?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -3096,6 +3115,7 @@ export type GQLQueryResolvers, ParentType, ContextType, Partial>; arenaCategories?: Resolver, ParentType, ContextType>; arenaCategory?: Resolver, ParentType, ContextType, RequireFields>; + arenaEnabledOrgs?: Resolver, ParentType, ContextType>; arenaRecentTopics?: Resolver, ParentType, ContextType>; arenaTopic?: Resolver, ParentType, ContextType, RequireFields>; arenaTopicsByUser?: Resolver, ParentType, ContextType, RequireFields>; @@ -3109,7 +3129,7 @@ export type GQLQueryResolvers, ParentType, ContextType, Partial>; coreElement?: Resolver, ParentType, ContextType, RequireFields>; coreElements?: Resolver>, ParentType, ContextType, Partial>; - examLockStatus?: Resolver; + examLockStatus?: Resolver; filmfrontpage?: Resolver, ParentType, ContextType>; folder?: Resolver>; folderResourceMeta?: Resolver, ParentType, ContextType, RequireFields>; @@ -3544,7 +3564,8 @@ export type GQLResolvers = { ConceptFolderResourceMeta?: GQLConceptFolderResourceMetaResolvers; ConceptLicense?: GQLConceptLicenseResolvers; ConceptResult?: GQLConceptResultResolvers; - ConfigMetaRestricted?: GQLConfigMetaRestrictedResolvers; + ConfigMetaBoolean?: GQLConfigMetaBooleanResolvers; + ConfigMetaStringList?: GQLConfigMetaStringListResolvers; Contributor?: GQLContributorResolvers; Copyright?: GQLCopyrightResolvers; CoreElement?: GQLCoreElementResolvers; diff --git a/yarn.lock b/yarn.lock index 3afa5a47..417492b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1506,10 +1506,10 @@ resolved "https://registry.yarnpkg.com/@ndla/licenses/-/licenses-7.1.3.tgz#3a826083fdf29cafe66b6197087c455d80a7a0ec" integrity sha512-3GNJxmAlFHnc4Q77sJL+RapEUcxxyBe9jDaFZ9f4miVpu3cIiZUhSXdqWR6E4C9EOKk86tuGftbr9BXIqREa+Q== -"@ndla/types-backend@^0.2.23": - version "0.2.23" - resolved "https://registry.yarnpkg.com/@ndla/types-backend/-/types-backend-0.2.23.tgz#dbd64746100e9ba4fc89332987ba3d89ed9fd503" - integrity sha512-jPU9uj/ItVyNnBCuPIqbSnOhfhVqC1nmEQzbV9cLCF0ijp7KmHpQ7UzfbG3zOg8/3GfuKVZT1Tk3vpVzlS4waQ== +"@ndla/types-backend@^0.2.26": + version "0.2.26" + resolved "https://registry.npmjs.org/@ndla/types-backend/-/types-backend-0.2.26.tgz#cf0e5ff76ce2893d7b54a475df4fa4865bf7a0a7" + integrity sha512-xSl2C20vXo1VvcOH7qWfsgg+T9sSmxInuPTcWgZPChKSX+Mo8nIZlz1Arz2gw9pg9YYDrMnMwKVD8B7i9xOihQ== "@ndla/types-embed@^4.0.0": version "4.0.0"