Skip to content

Simplify graph function paramDefs type#335

Merged
heyitsaamir merged 4 commits into
microsoft:mainfrom
Jesperholmbergmsft:jh/simplerParamDefs
Sep 10, 2025
Merged

Simplify graph function paramDefs type#335
heyitsaamir merged 4 commits into
microsoft:mainfrom
Jesperholmbergmsft:jh/simplerParamDefs

Conversation

@Jesperholmbergmsft

@Jesperholmbergmsft Jesperholmbergmsft commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

This PR changes the paramDefs type in the endpoint functions. The paramDefs values are used to construct the Graph HTTP request - for each parameter that the caller may supply, paramDefs decides whether they go in the path, the query string, or the request header.

The paramDefs type so far has been: { name: string; in: 'query' | 'header' | 'path' }>[]. So - an array of objects, each has a parameter name, and an in value to show where it goes.

The new type is: Partial<Record<'query' | 'header' | 'path', string[]>>; I'm pulling the 'in' values up a level to be a key in an object, the values being the parameters for that 'in'.

In practice, the paramDefs for an API before may have been:

    paramDefs: [
      { name: '$top', in: 'query' },
      { name: '$skip', in: 'query' },
      { name: '$search', in: 'query' },
      { name: '$filter', in: 'query' },
      { name: '$count', in: 'query' },
      { name: '$orderby', in: 'query' },
      { name: '$select', in: 'query' },
      { name: '$expand', in: 'query' },
    ],

And now the same is:

    paramDefs: {
      query: ['$top', '$skip', '$search', '$filter', '$count', '$orderby', '$select', '$expand'],
    },

This change has a surprisingly large impact on the size of code generated. After building the beta package, looking at the combined size of the .js files, they shrink from 6207kB to 5204kB. That's about 1/6th less code on disk.

There's no much improvement to the NPM package size, just a few kB, since the removed repetition compresses so well. But the uncompressed footprint makes it worthwhile all the same.

This change won't build until all endpoints are rebuilt, so in the first iteration I included only the changes to the generation script & the graph.call() method and a few updated endpoints - just enough to showcase the change.

In the second iteration, I regenerated all the endpoints for both beta and v.10 (schema commits 4e63218 and 3bdcc26, both published yesterday).

Comment thread packages/graph-endpoints/src/me/teamwork/associatedTeams/index.ts
Comment thread packages/graph-tools/src/endpoints.ts
Comment thread packages/graph-tools/templates/function-definition.ts.hbs
Comment thread packages/graph/src/utils/url.ts
Comment thread packages/graph/src/utils/url.ts
@Jesperholmbergmsft
Jesperholmbergmsft marked this pull request as ready for review September 8, 2025 23:12
heyitsaamir
heyitsaamir previously approved these changes Sep 10, 2025
Comment thread packages/graph/src/index.spec.ts Outdated
@heyitsaamir
heyitsaamir merged commit ce5b946 into microsoft:main Sep 10, 2025
5 checks passed
Copilot AI added a commit that referenced this pull request Feb 17, 2026
rido-min added a commit that referenced this pull request Feb 26, 2026
Adds reaction management capabilities via the Bot Framework API v3,
mirroring the teams.net implementation.

## Changes

**ReactionClient** (`/packages/api/src/clients/reaction/`)
- `add(conversationId, activityId, reactionType)` - PUT to
`/v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}`
- `remove(conversationId, activityId, reactionType)` - DELETE to same
endpoint
- Integrated into main `Client` class as `reactions` property

**ReactionType Model** (`/packages/api/src/models/reaction/`)
- Type-safe reaction values: `'like' | 'heart' | 'laugh' | 'surprised' |
'sad' | 'angry'`

**Breaking Change: MessageReactionActivity**
- Removed `addReaction()` and `removeReaction()` helper methods
- Reactions should now be managed via `ReactionClient` or set directly
on activity properties

**Example Application** (`/examples/reactions/`)
- Added comprehensive example bot demonstrating ReactionClient usage
- Shows how to add/remove reactions programmatically
- Demonstrates handling `messageReaction` activity events
- Includes interactive commands and detailed documentation

## Usage

```typescript
import { Client } from '@microsoft/teams.api';

const client = new Client(serviceUrl);

// Add a reaction
await client.reactions.add('conversationId', 'activityId', 'like');

// Remove a reaction
await client.reactions.remove('conversationId', 'activityId', 'like');

// MessageReactionActivity now requires direct property assignment
const activity = new MessageReactionActivity({
  reactionsAdded: [{ type: 'like', user: account }],
  reactionsRemoved: [{ type: 'heart', user: account }],
});
```

See the `examples/reactions` directory for a complete working example.

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: rido-min <[email protected]>
Co-authored-by: Rido <[email protected]>
@heyitsaamir heyitsaamir mentioned this pull request Mar 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants