Skip to content

Commit

Permalink
Merge pull request #1445 from the-deep/features/organization-rest-to-…
Browse files Browse the repository at this point in the history
…graphql

Create graphql node for creating new organization
  • Loading branch information
AdityaKhatri authored May 15, 2024
2 parents 6f6f6bb + 655d66d commit 0870533
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
31 changes: 31 additions & 0 deletions apps/organization/mutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import graphene
from organization.schema import OrganizationType
from organization.serializers import OrganizationGqSerializer

from utils.graphene.mutation import (
generate_input_type_for_serializer,
GrapheneMutation
)

from .models import Organization

OrganizationInputType = generate_input_type_for_serializer(
'OrganizationInputType',
serializer_class=OrganizationGqSerializer,
)


class OrganizationCreate(GrapheneMutation):
class Arguments:
data = OrganizationInputType(required=True)
model = Organization
result = graphene.Field(OrganizationType)
serializer_class = OrganizationGqSerializer

@classmethod
def check_permissions(cls, info, **kwargs):
return True # global permission is always True


class Mutation():
organization_create = OrganizationCreate.Field()
6 changes: 6 additions & 0 deletions apps/organization/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ class Meta:
model = Organization
fields = ('key', 'title', 'long_name',
'short_name', 'logo', 'organization_type', 'merged_as')


class OrganizationGqSerializer(UserResourceSerializer):
class Meta:
model = Organization
fields = ('title', 'long_name', 'url', 'short_name', 'logo', 'organization_type')
48 changes: 48 additions & 0 deletions apps/organization/tests/test_mutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from user.factories import UserFactory
from utils.graphene.tests import GraphQLTestCase


class TestOrganizationMutation(GraphQLTestCase):
def test_orgainization_query(self):
self.organization_query = '''
mutation MyMutation ($input : OrganizationInputType!)
{
organizationCreate(data: $input){
errors
ok
result{
id
longName
shortName
title
url
verified
}
}
}
'''

user = UserFactory.create()
minput = dict(
title="Test Organization",
shortName="Short Name",
longName="This is long name"
)

def _query_check(minput, **kwargs):
return self.query_check(
self.organization_query,
minput=minput,
**kwargs
)
# without login
_query_check(minput, assert_for_error=True)

# with login

self.force_login(user)

content = _query_check(minput)
self.assertEqual(content['data']['organizationCreate']['errors'], None)
self.assertEqual(content['data']['organizationCreate']['result']['title'], 'Test Organization')
self.assertEqual(content['data']['organizationCreate']['result']['verified'], False)
3 changes: 2 additions & 1 deletion deep/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from analysis import public_schema as analysis_public_schema
from user import mutation as user_mutation, schema as user_schema
from user_group import mutation as user_group_mutation, schema as user_group_schema
from organization import schema as organization_schema
from organization import schema as organization_schema, mutation as organization_mutation
from geo import schema as geo_schema
from notification import schema as notification_schema, mutation as notification_mutation
from assisted_tagging import schema as assisted_tagging_schema
Expand Down Expand Up @@ -72,6 +72,7 @@ class Mutation(
export_mutation.Mutation,
gallery_mutation.Mutation,
assessment_registry_mutation.Mutation,
organization_mutation.Mutation,
# --
graphene.ObjectType
):
Expand Down
16 changes: 16 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,7 @@ type MissingPredictionReviewType {
}

type Mutation {
organizationCreate(data: OrganizationInputType!): OrganizationCreate
createAssessmentRegSummaryIssue(data: AssessmentRegistrySummaryIssueCreateInputType!): AssessmentRegistryCreateIssue
fileUpload(data: FileUploadInputType!): UploadFile
genericExportCreate(data: GenericExportCreateInputType!): CreateUserGenericExport
Expand Down Expand Up @@ -5048,6 +5049,21 @@ enum NotificationTypeEnum {
ENTRY_REVIEW_COMMENT_MODIFY
}

type OrganizationCreate {
errors: [GenericScalar!]
ok: Boolean
result: OrganizationType
}

input OrganizationInputType {
title: String!
longName: String
url: String
shortName: String
logo: ID
organizationType: ID
}

type OrganizationListType {
results: [OrganizationType!]
totalCount: Int
Expand Down

0 comments on commit 0870533

Please sign in to comment.