Skip to content

Commit 1775b7b

Browse files
committed
add snapshot tests for minification
1 parent 0f4072e commit 1775b7b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

crates/apollo-mcp-server/src/introspection/minify.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,27 @@ fn normalize_description(desc: &str) -> String {
253253
let re = WHITESPACE_PATTERN.get_or_init(|| Regex::new(r"\s+").expect("regex pattern compiles"));
254254
re.replace_all(desc, "").to_string()
255255
}
256+
257+
#[cfg(test)]
258+
mod tests {
259+
use super::*;
260+
261+
const TEST_SCHEMA: &str = include_str!("tools/testdata/schema.graphql");
262+
263+
#[test]
264+
fn test_minify_schema() {
265+
let schema = apollo_compiler::schema::Schema::parse(TEST_SCHEMA, "schema.graphql")
266+
.expect("Failed to parse schema")
267+
.validate()
268+
.expect("Failed to validate schema");
269+
270+
let minified = schema
271+
.types
272+
.iter()
273+
.map(|(_, type_)| format!("{}: {}", type_.name().as_str(), type_.minify()))
274+
.collect::<Vec<String>>()
275+
.join("\n");
276+
277+
insta::assert_snapshot!(minified);
278+
}
279+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
source: crates/apollo-mcp-server/src/introspection/minify.rs
3+
expression: minified
4+
---
5+
__Schema: T:"AGraphQLSchemadefinesthecapabilitiesofaGraphQLserver.Itexposesallavailabletypesanddirectivesontheserver,aswellastheentrypointsforquery,mutation,andsubscriptionoperations."__Schema:description:s,"Alistofalltypessupportedbythisserver."types:[__Type],"Thetypethatqueryoperationswillberootedat."queryType:__Type!,"Ifthisserversupportsmutation,thetypethatmutationoperationswillberootedat."mutationType:__Type,"Ifthisserversupportsubscription,thetypethatsubscriptionoperationswillberootedat."subscriptionType:__Type,"Alistofalldirectivessupportedbythisserver."directives:[__Directive]
6+
__Type: T:"ThefundamentalunitofanyGraphQLSchemaisthetype.TherearemanykindsoftypesinGraphQLasrepresentedbythe`__TypeKind`enum.Dependingonthekindofatype,certainfieldsdescribeinformationaboutthattype.Scalartypesprovidenoinformationbeyondaname,descriptionandoptional`specifiedByURL`,whileEnumtypesprovidetheirvalues.ObjectandInterfacetypesprovidethefieldstheydescribe.Abstracttypes,UnionandInterface,providetheObjecttypespossibleatruntime.ListandNonNulltypescomposeothertypes."__Type:kind:__TypeKind!,name:s,description:s,fields(includeDeprecated:b):[__Field],interfaces:[__Type],possibleTypes:[__Type],enumValues(includeDeprecated:b):[__EnumValue],inputFields(includeDeprecated:b):[__InputValue],ofType:__Type,specifiedByURL:s
7+
__TypeKind: E:"Anenumdescribingwhatkindoftypeagiven`__Type`is."__TypeKind:SCALAR,OBJECT,INTERFACE,UNION,ENUM,INPUT_OBJECT,LIST,NON_NULL
8+
__Field: T:"ObjectandInterfacetypesaredescribedbyalistofFields,eachofwhichhasaname,potentiallyalistofarguments,andareturntype."__Field:name:s!,description:s,args(includeDeprecated:b):[__InputValue],type:__Type!,isDeprecated:b!,deprecationReason:s
9+
__InputValue: T:"ArgumentsprovidedtoFieldsorDirectivesandtheinputfieldsofanInputObjectarerepresentedasInputValueswhichdescribetheirtypeandoptionallyadefaultvalue."__InputValue:name:s!,description:s,type:__Type!,"AGraphQL-formattedstringrepresentingthedefaultvalueforthisinputvalue."defaultValue:s,isDeprecated:b!,deprecationReason:s
10+
__EnumValue: T:"OnepossiblevalueforagivenEnum.Enumvaluesareuniquevalues,notaplaceholderforastringornumericvalue.HoweveranEnumvalueisreturnedinaJSONresponseasastring."__EnumValue:name:s!,description:s,isDeprecated:b!,deprecationReason:s
11+
__Directive: T:"ADirectiveprovidesawaytodescribealternateruntimeexecutionandtypevalidationbehaviorinaGraphQLdocument.Insomecases,youneedtoprovideoptionstoalterGraphQL'sexecutionbehaviorinwaysfieldargumentswillnotsuffice,suchasconditionallyincludingorskippingafield.Directivesprovidethisbydescribingadditionalinformationtotheexecutor."__Directive:name:s!,description:s,locations:[__DirectiveLocation],args(includeDeprecated:b):[__InputValue],isRepeatable:b!
12+
__DirectiveLocation: E:"ADirectivecanbeadjacenttomanypartsoftheGraphQLlanguage,a__DirectiveLocationdescribesonesuchpossibleadjacencies."__DirectiveLocation:QUERY,MUTATION,SUBSCRIPTION,FIELD,FRAGMENT_DEFINITION,FRAGMENT_SPREAD,INLINE_FRAGMENT,VARIABLE_DEFINITION,SCHEMA,SCALAR,OBJECT,FIELD_DEFINITION,ARGUMENT_DEFINITION,INTERFACE,UNION,ENUM,ENUM_VALUE,INPUT_OBJECT,INPUT_FIELD_DEFINITION
13+
Int: i
14+
Float: f
15+
String: s
16+
Boolean: b
17+
ID: d
18+
DateTime: DateTime
19+
JSON: JSON
20+
Upload: Upload
21+
UserRole: E:UserRole:ADMIN,MODERATOR,USER,GUEST
22+
ContentStatus: E:ContentStatus:DRAFT,PUBLISHED,ARCHIVED,DELETED
23+
NotificationPriority: E:NotificationPriority:LOW,MEDIUM,HIGH,URGENT
24+
MediaType: E:MediaType:IMAGE,VIDEO,AUDIO,DOCUMENT
25+
Node: F:Node:id:d!,createdAt:DateTime!,updatedAt:DateTime!
26+
Content: F:Content:id:d!,title:s!,status:ContentStatus!,author:User!,metadata:JSON
27+
User: T:User<Node>:id:d!,createdAt:DateTime!,updatedAt:DateTime!,username:s!,email:s!,role:UserRole!,profile:UserProfile,posts:[Post],comments:[Comment],notifications:[Notification],preferences:UserPreferences!
28+
UserProfile: T:UserProfile:firstName:s,lastName:s,bio:s,avatar:Media,socialLinks:[SocialLink],location:Location
29+
Location: T:Location:country:s!,city:s,coordinates:Coordinates
30+
Coordinates: T:Coordinates:latitude:f!,longitude:f!
31+
SocialLink: T:SocialLink:platform:s!,url:s!,verified:b!
32+
Post: T:Post<Node,Content>:id:d!,createdAt:DateTime!,updatedAt:DateTime!,title:s!,content:s!,status:ContentStatus!,author:User!,metadata:JSON,comments:[Comment],media:[Media],tags:[Tag],analytics:PostAnalytics!
33+
Comment: T:Comment<Node>:id:d!,createdAt:DateTime!,updatedAt:DateTime!,content:s!,author:User!,post:Post!,parentComment:Comment,replies:[Comment],reactions:[Reaction]
34+
Media: T:Media:id:d!,type:MediaType!,url:s!,thumbnail:s,metadata:MediaMetadata!,uploader:User!
35+
MediaMetadata: T:MediaMetadata:size:i!,format:s!,dimensions:Dimensions,duration:i
36+
Dimensions: T:Dimensions:width:i!,height:i!
37+
Tag: T:Tag:id:d!,name:s!,slug:s!,description:s,posts:[Post]
38+
Reaction: T:Reaction:id:d!,type:s!,user:User!,comment:Comment!,createdAt:DateTime!
39+
Notification: T:Notification:id:d!,type:s!,priority:NotificationPriority!,message:s!,recipient:User!,read:b!,createdAt:DateTime!,metadata:JSON
40+
PostAnalytics: T:PostAnalytics:views:i!,likes:i!,shares:i!,comments:i!,engagement:f!,demographics:Demographics!
41+
Demographics: T:Demographics:ageGroups:[AgeGroup],locations:[LocationStats],devices:[DeviceStats]
42+
AgeGroup: T:AgeGroup:range:s!,percentage:f!
43+
LocationStats: T:LocationStats:country:s!,count:i!
44+
DeviceStats: T:DeviceStats:type:s!,count:i!
45+
UserPreferences: T:UserPreferences:theme:s!,language:s!,notifications:NotificationPreferences!,privacy:PrivacySettings!
46+
NotificationPreferences: T:NotificationPreferences:email:b!,push:b!,sms:b!,frequency:s!
47+
PrivacySettings: T:PrivacySettings:profileVisibility:s!,showEmail:b!,showLocation:b!
48+
CreateUserInput: I:CreateUserInput:username:s!,email:s!,password:s!,role:UserRole,profile:CreateUserProfileInput
49+
CreateUserProfileInput: I:CreateUserProfileInput:firstName:s,lastName:s,bio:s,location:CreateLocationInput
50+
CreateLocationInput: I:CreateLocationInput:country:s!,city:s,coordinates:CreateCoordinatesInput
51+
CreateCoordinatesInput: I:CreateCoordinatesInput:latitude:f!,longitude:f!
52+
CreatePostInput: I:CreatePostInput:title:s!,content:s!,status:ContentStatus,tags:[s],media:[Upload]
53+
UpdatePostInput: I:UpdatePostInput:title:s,content:s,status:ContentStatus,tags:[s]
54+
CreateCommentInput: I:CreateCommentInput:content:s!,postId:d!,parentCommentId:d
55+
NotificationFilter: I:NotificationFilter:priority:NotificationPriority,read:b,type:s,startDate:DateTime,endDate:DateTime
56+
Query: T:Query:node(id:d!):Node,user(id:d!):User,post(id:d!):Post,postsOld(filter:[d]):[Post]@D("Usepostsinstead"),posts(filter:PostFilter):[Post],comments(postId:d!):[Comment],notifications(filter:NotificationFilter):[Notification],search(query:s!):SearchResult!
57+
Mutation: T:Mutation:createUser(input:CreateUserInput!):User!,createPost(input:CreatePostInput!):Post!,updatePost(id:d!,input:UpdatePostInput!):Post!,createComment(input:CreateCommentInput!):Comment!,deletePost(id:d!):b!,uploadMedia(file:Upload!):Media!,updateUserPreferences(id:d!,preferences:UserPreferencesInput!):UserPreferences!
58+
Subscription: T:Subscription:postUpdated(id:d!):Post!,newComment(postId:d!):Comment!,notificationReceived(userId:d!):Notification!
59+
SearchResult: U:SearchResult:User,Post,Comment,Tag
60+
PostFilter: I:PostFilter:status:ContentStatus,authorId:d,tags:[s],dateRange:DateRangeInput
61+
DateRangeInput: I:DateRangeInput:start:DateTime!,end:DateTime!
62+
UserPreferencesInput: I:UserPreferencesInput:theme:s,language:s,notifications:NotificationPreferencesInput,privacy:PrivacySettingsInput
63+
NotificationPreferencesInput: I:NotificationPreferencesInput:email:b,push:b,sms:b,frequency:s
64+
PrivacySettingsInput: I:PrivacySettingsInput:profileVisibility:s,showEmail:b,showLocation:b

crates/apollo-mcp-server/src/introspection/tools/testdata/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ type Query {
268268
node(id: ID!): Node
269269
user(id: ID!): User
270270
post(id: ID!): Post
271+
postsOld(filter: [ID!]) : [Post!]! @deprecated(reason: "Use posts instead")
271272
posts(filter: PostFilter): [Post!]!
272273
comments(postId: ID!): [Comment!]!
273274
notifications(filter: NotificationFilter): [Notification!]!

0 commit comments

Comments
 (0)