Page tree
Skip to end of metadata
Go to start of metadata

Update

Updating a Space can now be done when authenticated as an application or as a user.

The "updateSpace" mutation updates a Space title or members or both.The update to members defines whether the relevant members should be added or removed.

The org.opencode4workspace.builders.SpaceUpdateGraphQLMutation has three simple static helper methods:

  • Updating the title - buildUpdateSpaceMutationChangeTitle(String, String)
  • Updating the members, buildUpdateSpaceMutationChangeMembers(String, List<String>, UpdateSpaceMemberOperation)
  • Updating both title and members, buildUpdateSpaceMutationChangeTitleAndMembers(String, String, List<String>, UpdateSpaceMemberOperation).

Similar methods are also available from WWClient and WWGraphQLEndpoint. These will return the relevant object:

  • Updating a title returns the Space object
  • Updating members returns an ArrayList of member IDs updated
  • Updating both title and members returns an UpdateSpaceContainer containing an ArrayList of members IDs updated and the Space object that was modified.

For greater control, create the InputDataSenderBuilder and ObjectDataSenderBuilder(s) manually. Create an InputDataSenderBuilder for the Space.UPDATE_SPACE_MUTATION_NAME object, adding the Space ID, new title (if required), members to update (if required) and whether to add or remove. An UpdateSpaceFields enum is available to avoid typos on the field names and an UpdateSpaceMemberOperation enum is available to avoid typos on whether to add or remove.

Create a ScalarDataSenderBuilder for the MEMBER_IDS_CHANGED_FIELD if you need to return an array of member IDs updated.

Create an ObjectDataSenderBuilder for the Space.ONE_SPACE_QUERY_OBJECT_NAME, passing in Space fields and children, if you need to return the Space object.

Instantiate a new SpaceUpdateGraphQLMutation passing in the InputDataSenderBuilder and ObjectDataSenderBuilder(s) as parameters. Then pass this to WWClient.updateSpaceWithQuery().

Basic updateSpaceTitle
Space space = client.updateSpaceTitle("58935f40f4b0f36a34bbf40f", "My New Space Title");
assert "My New Space Title".equals(space.getTitle());
Basic updateSpaceMembers
ArrayList<String> members = new ArrayList<String>();
members.add("7bf6c84f-861c-43df-816a-85748766912e");
members.add("1d1bf268-c263-4eea-aaec-e2dbeaa2fb71");
ArrayList<String> membersUpdated = client.updateSpaceMembers("58935f40f4b0f36a34bbf40f", members, UpdateSpaceMemberOperation.ADD);
assert membersUpdated.size == members.size();
Basic updateSpaceTitleAndMembers
 ArrayList<String> members = new ArrayList<String>();
members.add("7bf6c84f-861c-43df-816a-85748766912e");
members.add("1d1bf268-c263-4eea-aaec-e2dbeaa2fb71");
UpdateSpaceContainer result = client.updateSpaceMembers("58935f40f4b0f36a34bbf40f", "My New Space Title", members, UpdateSpaceMemberOperation.REMOVE);
// memberIdsChanged is String[]
assert result.getMemberIdsChanged().length() == members.size();
assert "My New Space Title".equals(result.getSpace().getTitle());
updateSpaceWithQuery (Title only)
InputDataSenderBuilder spaceInput = new InputDataSenderBuilder(Space.UPDATE_SPACE_MUTATION_NAME);
spaceInput.addField(UpdateSpaceFields.ID, spaceId);
spaceInput.addField(UpdateSpaceFields.TITLE, "My New Space title");
ObjectDataSenderBuilder returnObject = new ObjectDataSenderBuilder(Space.ONE_SPACE_QUERY_OBJECT_NAME);
returnObject.addField(SpaceFields.TITLE);
returnObject.addField(SpaceFields.ID);
SpaceUpdateGraphQLMutation mutationObject = new SpaceUpdateGraphQLMutation(spaceInput, returnObject);
UpdateSpaceContainer result = client.updateSpaceWithMutation(new GraphQLRequest(mutationObject));
assert "My New Space Title".equals(result.getSpace().getTitle();
assert spaceId.equals(result.getSpace().getId());
updateSpaceWithQuery Title and Members
 ArrayList<String> members = new ArrayList<String>();
members.add("ae81bc5d-70fa-4bdb-bab7-29f4df10ddf3y");
InputDataSenderBuilder spaceInput = new InputDataSenderBuilder(Space.UPDATE_SPACE_MUTATION_NAME);
spaceInput.addField(UpdateSpaceFields.ID, spaceId);
spaceInput.addField(UpdateSpaceFields.TITLE, "My new title");
spaceInput.addField(UpdateSpaceFields.MEMBERS, members);
spaceInput.addField(UpdateSpaceFields.MEMBER_OPERATION, UpdateSpaceMemberOperation.ADD);
ObjectDataSenderBuilder returnObject1 = new ObjectDataSenderBuilder(Space.ONE_SPACE_QUERY_OBJECT_NAME);
returnObject1.addField(SpaceFields.TITLE);
returnObject1.addField(SpaceFields.ID);
ScalarDataSenderBuilder returnObject2 = new ScalarDataSenderBuilder(MEMBER_IDS_CHANGED_FIELD);
SpaceUpdateGraphQLMutation mutationObject = new SpaceUpdateGraphQLMutation(spaceInput, returnObject1, returnObject2);
UpdateSpaceContainer result = client.updateSpaceWithMutation(new GraphQLRequest(mutationObject));
assert "My New Space Title".equals(result.getSpace().getTitle();
assert spaceId.equals(result.getSpace().getId());
// memberIdsChanged is String[]
assert result.getMemberIdsChanged().length() == members.size();
Write a comment…