diff --git a/packages/server/graphql/private/queries/getSAMLForDomain.ts b/packages/server/graphql/private/queries/getSAMLForDomain.ts new file mode 100644 index 00000000000..6364ef9bad8 --- /dev/null +++ b/packages/server/graphql/private/queries/getSAMLForDomain.ts @@ -0,0 +1,23 @@ +import getKysely from '../../../postgres/getKysely' +import standardError from '../../../utils/standardError' +import {QueryResolvers} from '../resolverTypes' + +const getSAMLForDomain: QueryResolvers['getSAMLForDomain'] = async (_parent, {domain}) => { + const pg = getKysely() + + const samlResult = await pg + .selectFrom('SAML') + .innerJoin('SAMLDomain', 'SAML.id', 'SAMLDomain.samlId') + .selectAll('SAML') + .where('SAMLDomain.domain', '=', domain.toLowerCase()) + .executeTakeFirst() + + if (!samlResult) { + return standardError(new Error('No SAML configuration found for domain')) + } + return { + saml: samlResult + } +} + +export default getSAMLForDomain diff --git a/packages/server/graphql/private/typeDefs/GetSAMLForDomainPayload.graphql b/packages/server/graphql/private/typeDefs/GetSAMLForDomainPayload.graphql new file mode 100644 index 00000000000..db857c3b38f --- /dev/null +++ b/packages/server/graphql/private/typeDefs/GetSAMLForDomainPayload.graphql @@ -0,0 +1,4 @@ +""" +Return value for getSAMLForDomain, which could be an error +""" +union GetSAMLForDomainPayload = ErrorPayload | GetSAMLForDomainSuccess diff --git a/packages/server/graphql/private/typeDefs/GetSAMLForDomainSuccess.graphql b/packages/server/graphql/private/typeDefs/GetSAMLForDomainSuccess.graphql new file mode 100644 index 00000000000..fb2d42a71a4 --- /dev/null +++ b/packages/server/graphql/private/typeDefs/GetSAMLForDomainSuccess.graphql @@ -0,0 +1,6 @@ +type GetSAMLForDomainSuccess { + """ + The SAML configuration + """ + saml: SAML! +} diff --git a/packages/server/graphql/private/typeDefs/Query.graphql b/packages/server/graphql/private/typeDefs/Query.graphql index fda75c5b187..0e1b7de3c5d 100644 --- a/packages/server/graphql/private/typeDefs/Query.graphql +++ b/packages/server/graphql/private/typeDefs/Query.graphql @@ -138,4 +138,11 @@ type Query { """ includeInactive: Boolean! = false ): [Organization!] + + getSAMLForDomain( + """ + the domain to get the SAML record for + """ + domain: String! + ): GetSAMLForDomainPayload }