@@ -172,8 +172,60 @@ type createGraphAdditionalOptions struct {
172172
173173// CreateGraph creates a new graph with given name and options, and opens a connection to it.
174174// If a graph with given name already exists within the database, a DuplicateError is returned.
175- // todo test
176175func (d * database ) CreateGraph (ctx context.Context , name string , options * CreateGraphOptions ) (Graph , error ) {
176+ input := createGraphOptions {
177+ Name : name ,
178+ }
179+ if options != nil {
180+ input .OrphanVertexCollections = options .OrphanVertexCollections
181+ input .EdgeDefinitions = options .EdgeDefinitions
182+ input .IsSmart = options .IsSmart
183+ if options .ReplicationFactor == SatelliteGraph {
184+ input .Options = & createGraphAdditionalOptions {
185+ SmartGraphAttribute : options .SmartGraphAttribute ,
186+ ReplicationFactor : graphReplicationFactor (options .ReplicationFactor ),
187+ IsDisjoint : options .IsDisjoint ,
188+ Satellites : options .Satellites ,
189+ }
190+ } else if options .SmartGraphAttribute != "" || options .NumberOfShards != 0 {
191+ input .Options = & createGraphAdditionalOptions {
192+ SmartGraphAttribute : options .SmartGraphAttribute ,
193+ NumberOfShards : options .NumberOfShards ,
194+ ReplicationFactor : graphReplicationFactor (options .ReplicationFactor ),
195+ WriteConcern : options .WriteConcern ,
196+ IsDisjoint : options .IsDisjoint ,
197+ Satellites : options .Satellites ,
198+ }
199+ }
200+ }
201+ req , err := d .conn .NewRequest ("POST" , path .Join (d .relPath (), "_api/gharial" ))
202+ if err != nil {
203+ return nil , WithStack (err )
204+ }
205+ if _ , err := req .SetBody (input ); err != nil {
206+ return nil , WithStack (err )
207+ }
208+ resp , err := d .conn .Do (ctx , req )
209+ if err != nil {
210+ return nil , WithStack (err )
211+ }
212+ if err := resp .CheckStatus (201 , 202 ); err != nil {
213+ return nil , WithStack (err )
214+ }
215+ var data getGraphResponse
216+ if err := resp .ParseBody ("" , & data ); err != nil {
217+ return nil , WithStack (err )
218+ }
219+ g , err := newGraph (data .Graph , d )
220+ if err != nil {
221+ return nil , WithStack (err )
222+ }
223+ return g , nil
224+ }
225+
226+ // CreateGraphV2 creates a new graph with given name and options, and opens a connection to it.
227+ // If a graph with given name already exists within the database, a DuplicateError is returned.
228+ func (d * database ) CreateGraphV2 (ctx context.Context , name string , options * CreateGraphOptions ) (Graph , error ) {
177229 input := createGraphOptions {
178230 Name : name ,
179231 }
0 commit comments